Rust SDK Example Code
For sample code which explains the core concepts of how to use the SDK, see:
Below are additional resources and a complete list of runnable examples included in the SDK repository.
Running Examples
Section titled “Running Examples”The examples directory in the SDK repository contains a wide range of examples you can run and customize to your needs.
To run an example:
git clone https://github.com/aptos-labs/aptos-rust-sdk.gitcd aptos-rust-sdkcargo run --example transfer --features "ed25519,faucet"Basic Operations
Section titled “Basic Operations”These examples demonstrate fundamental interactions with the Aptos blockchain such as transferring tokens, checking balances, and querying on-chain data.
| Example | Description | Features |
|---|---|---|
transfer | Transfer APT between two accounts on testnet | ed25519, faucet |
balance_checker | Query the APT balance of one or more accounts | ed25519 |
view_function | Call on-chain view functions and parse return values | ed25519 |
transaction_data | Fetch and display detailed transaction data by hash or version | ed25519, faucet |
transaction_waiting | Submit a transaction and wait for confirmation with status polling | ed25519, faucet |
Account Management
Section titled “Account Management”These examples cover account creation, multi-key configurations, and multisig account workflows.
| Example | Description | Features |
|---|---|---|
account_management | Create, fund, and rotate authentication keys for accounts | ed25519, faucet |
multi_key_account | Create an account controlled by multiple keys with a signing threshold | ed25519, secp256k1, faucet |
multi_sig_account | Set up and use a multisig account with multiple owners | ed25519, faucet |
multisig_v2 | Use the v2 multisig module for on-chain governance-style proposals | ed25519, faucet |
Advanced Transactions
Section titled “Advanced Transactions”These examples show more sophisticated transaction patterns including entry functions, simulation, multi-agent transactions, and sponsored transactions.
| Example | Description | Features |
|---|---|---|
entry_function | Build and submit entry function payloads with typed arguments | ed25519, faucet |
advanced_transactions | Demonstrate batch submission, gas tuning, and expiration control | ed25519, faucet |
simulation | Simulate a transaction to estimate gas and verify execution without committing | ed25519, faucet |
multi_agent | Build transactions requiring signatures from multiple sender accounts | ed25519, faucet |
sponsored_transaction | Submit a transaction where a separate account pays the gas fees | ed25519, faucet |
script_transaction | Compile and execute a Move script as a transaction payload | ed25519, faucet |
Smart Contracts
Section titled “Smart Contracts”These examples demonstrate deploying Move modules, calling contract functions, reading contract state, and generating type-safe bindings.
| Example | Description | Features |
|---|---|---|
deploy_module | Compile and publish a Move module to the blockchain | ed25519, faucet |
call_contract | Invoke entry functions on a deployed Move module | ed25519, faucet |
read_contract_state | Read resources and data stored by a Move module | ed25519 |
contract_bindings | Use the aptos_contract! macro to generate type-safe Rust bindings for a module | ed25519, faucet, macros |
codegen | Auto-generate Rust types and functions from on-chain module ABIs | ed25519, macros |
nft_operations | Create collections, mint tokens, and transfer digital assets | ed25519, faucet |
Data Queries
Section titled “Data Queries”These examples show how to query events and indexed data from the Aptos network.
| Example | Description | Features |
|---|---|---|
event_queries | Listen for and filter on-chain events by type and account | ed25519 |
indexer_queries | Query the Aptos indexer for aggregated token, coin, and transaction data | ed25519, indexer |
Additional Resources
Section titled “Additional Resources”- SDK source code — Browse the implementation with in-line documentation and comments.
- docs.rs reference — Complete API documentation with search and cross-referencing.
- End-to-end tests — The most comprehensive set of code exercising SDK functionality, useful as a reference for advanced usage patterns.