Loading...
Loading...
Generates secure Aptos Move V2 smart contracts with Object model, Digital Asset integration, security patterns, and storage type guidance. Includes comprehensive storage decision framework for optimal data structure selection. Triggers on: 'write contract', 'create NFT collection', 'build marketplace', 'implement minting', 'generate Move module', 'create token contract', 'build DAO', 'implement staking'. Ask storage questions when: 'store', 'track', 'registry', 'mapping', 'list', 'collection'.
npx skill4agent add iskysun96/aptos-agent-skills write-contractsaptos_token_objects::collectionaptos_token_objects::tokenObject<AptosToken>Object<T>aptos_token::token../../../patterns/move/DIGITAL_ASSETS.mdObject<T>Object<T>object::owner(obj) == signer::address_of(user)assert!(signer::address_of(user) == expected, E_UNAUTHORIZED)&mutobj.is_owner(user)selfvector[index]vector::borrow()@marketplace_addr#[view](seller, price, timestamp)#[view]/// comment#[view]#[view]///search-aptos-examplessecurity-auditstruct MyObject has key {
name: String,
transfer_ref: object::TransferRef,
delete_ref: object::DeleteRef,
}
// Error constants
const E_NOT_OWNER: u64 = 1;
const E_EMPTY_STRING: u64 = 2;
const E_NAME_TOO_LONG: u64 = 3;
// Configuration constants
const MAX_NAME_LENGTH: u64 = 100;
/// Create object with proper pattern
public fun create_my_object(creator: &signer, name: String): Object<MyObject> {
// 1. Create object
let constructor_ref = object::create_object(signer::address_of(creator));
// 2. Generate ALL refs you'll need BEFORE constructor_ref is destroyed
let transfer_ref = object::generate_transfer_ref(&constructor_ref);
let delete_ref = object::generate_delete_ref(&constructor_ref);
// 3. Get object signer
let object_signer = object::generate_signer(&constructor_ref);
// 4. Store data in object
move_to(&object_signer, MyObject {
name,
transfer_ref,
delete_ref,
});
// 5. Return typed object reference (ConstructorRef automatically destroyed)
object::object_from_constructor_ref<MyObject>(&constructor_ref)
}
/// Update with ownership verification
public entry fun update_object(
owner: &signer,
obj: Object<MyObject>,
new_name: String
) acquires MyObject {
// ✅ ALWAYS: Verify ownership
assert!(object::owner(obj) == signer::address_of(owner), E_NOT_OWNER);
// ✅ ALWAYS: Validate inputs
assert!(string::length(&new_name) > 0, E_EMPTY_STRING);
assert!(string::length(&new_name) <= MAX_NAME_LENGTH, E_NAME_TOO_LONG);
// Safe to proceed
let obj_data = borrow_global_mut<MyObject>(object::object_address(&obj));
obj_data.name = new_name;
}struct ListingInfo has store, drop, copy {
seller: address,
price: u64,
listed_at: u64,
}
/// Accessor function - tests cannot access struct fields directly
/// Use tuple returns for multiple fields
#[view]
public fun get_listing_details(nft_addr: address): (address, u64, u64) acquires Listings {
let listings = borrow_global<Listings>(get_marketplace_address());
assert!(table::contains(&listings.items, nft_addr), E_NOT_LISTED);
let listing = table::borrow(&listings.items, nft_addr);
(listing.seller, listing.price, listing.listed_at)
}
/// Single-field accessor when only one value needed
#[view]
public fun get_staked_amount(user_addr: address): u64 acquires Stakes {
let stakes = borrow_global<Stakes>(get_vault_address());
if (table_with_length::contains(&stakes.items, user_addr)) {
table_with_length::borrow(&stakes.items, user_addr).amount
} else {
0
}
}module my_addr::my_module {
// ============ Imports ============
use std::signer;
use std::string::String;
use aptos_framework::object::{Self, Object};
use aptos_framework::event;
// ============ Events ============
#[event]
struct ItemCreated has drop, store {
item: address,
creator: address,
}
// ============ Structs ============
// Define your data structures
// ============ Constants ============
const E_NOT_OWNER: u64 = 1;
const E_UNAUTHORIZED: u64 = 2;
// ============ Init Module ============
fun init_module(deployer: &signer) {
// Initialize global state, registries, etc.
}
// ============ Public Entry Functions ============
// User-facing functions
// ============ Public Functions ============
// Composable functions
// ============ Private Functions ============
// Internal helpers
}references/storage-decision-tree.md.length()references/storage-patterns.md| Pattern | Recommended Storage |
|---|---|
| User registry | |
| Staking records | |
| Leaderboard | |
| Transaction log | |
| Whitelist (<100) | |
| Voting records | |
| Config (<50) | |
| DAO proposals | |
| Asset collection | |
Table<address, StakeInfo>BigOrderedMap<u64, address>allocate_spare_slotsreferences/aptos_token::token@my_addr"0x...".env~/.aptos/config.yaml| Scenario | Check | Error Code |
|---|---|---|
| Zero amounts | | E_ZERO_AMOUNT |
| Excessive amounts | | E_AMOUNT_TOO_HIGH |
| Empty vectors | | E_EMPTY_VECTOR |
| Empty strings | | E_EMPTY_STRING |
| Strings too long | | E_STRING_TOO_LONG |
| Zero address | | E_ZERO_ADDRESS |
| Overflow | | E_OVERFLOW |
| Underflow | | E_UNDERFLOW |
| Division by zero | | E_DIVISION_BY_ZERO |
| Unauthorized access | | E_UNAUTHORIZED |
| Not object owner | | E_NOT_OWNER |
references/storage-decision-tree.mdreferences/storage-patterns.mdreferences/storage-types.mdreferences/storage-gas-optimization.mdreferences/object-patterns.mdreferences/access-control.mdreferences/safe-arithmetic.mdreferences/initialization.mdreferences/events.mdreferences/v2-syntax.mdreferences/complete-example.md../../../patterns/move/DIGITAL_ASSETS.md../../../patterns/move/OBJECTS.md../../../patterns/move/SECURITY.md../../../patterns/move/MOVE_V2_SYNTAX.mdsearch-aptos-examplesgenerate-testssecurity-audit