aptos-sdk-macros
Procedural macros for generating type-safe Aptos contract bindings at compile time.
Features
aptos_contract!- Generate contract bindings from inline ABIaptos_contract_file!- Generate contract bindings from ABI file#[derive(MoveStruct)]- Derive Move struct serialization- Compile-time type checking for contract interactions
Usage
Contract Bindings from ABI
use aptos_contract;
// From inline ABI JSON
aptos_contract!
// Use the generated bindings
let payload = transfer?;
let balance = view_balance.await?;
From ABI File
use aptos_contract_file;
// Load ABI from file at compile time
aptos_contract_file!;
With Move Source (Better Parameter Names)
use aptos_contract;
aptos_contract!
Generated Code
For a module with entry functions transfer and mint, and view function balance:
Address Override
The generated bindings support address override for deploying to different addresses:
// Use default address from ABI
let coin = new;
// Override for testnet deployment
let coin = with_address;
// All methods use the configured address
let payload = coin.transfer?;
View Function Variants
Each view function generates two variants:
view_<name>()- Returns typed values using BCS (recommended for type safety)view_<name>_json()- Returns raw JSON (useful for debugging/inspection)
## License
Apache-2.0