Skip to content

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.

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:

Terminal window
git clone https://github.com/aptos-labs/aptos-rust-sdk.git
cd aptos-rust-sdk
cargo run --example transfer --features "ed25519,faucet"

These examples demonstrate fundamental interactions with the Aptos blockchain such as transferring tokens, checking balances, and querying on-chain data.

ExampleDescriptionFeatures
transferTransfer APT between two accounts on testneted25519, faucet
balance_checkerQuery the APT balance of one or more accountsed25519
view_functionCall on-chain view functions and parse return valuesed25519
transaction_dataFetch and display detailed transaction data by hash or versioned25519, faucet
transaction_waitingSubmit a transaction and wait for confirmation with status pollinged25519, faucet

These examples cover account creation, multi-key configurations, and multisig account workflows.

ExampleDescriptionFeatures
account_managementCreate, fund, and rotate authentication keys for accountsed25519, faucet
multi_key_accountCreate an account controlled by multiple keys with a signing thresholded25519, secp256k1, faucet
multi_sig_accountSet up and use a multisig account with multiple ownersed25519, faucet
multisig_v2Use the v2 multisig module for on-chain governance-style proposalsed25519, faucet

These examples show more sophisticated transaction patterns including entry functions, simulation, multi-agent transactions, and sponsored transactions.

ExampleDescriptionFeatures
entry_functionBuild and submit entry function payloads with typed argumentsed25519, faucet
advanced_transactionsDemonstrate batch submission, gas tuning, and expiration controled25519, faucet
simulationSimulate a transaction to estimate gas and verify execution without committinged25519, faucet
multi_agentBuild transactions requiring signatures from multiple sender accountsed25519, faucet
sponsored_transactionSubmit a transaction where a separate account pays the gas feesed25519, faucet
script_transactionCompile and execute a Move script as a transaction payloaded25519, faucet

These examples demonstrate deploying Move modules, calling contract functions, reading contract state, and generating type-safe bindings.

ExampleDescriptionFeatures
deploy_moduleCompile and publish a Move module to the blockchained25519, faucet
call_contractInvoke entry functions on a deployed Move moduleed25519, faucet
read_contract_stateRead resources and data stored by a Move moduleed25519
contract_bindingsUse the aptos_contract! macro to generate type-safe Rust bindings for a moduleed25519, faucet, macros
codegenAuto-generate Rust types and functions from on-chain module ABIsed25519, macros
nft_operationsCreate collections, mint tokens, and transfer digital assetsed25519, faucet

These examples show how to query events and indexed data from the Aptos network.

ExampleDescriptionFeatures
event_queriesListen for and filter on-chain events by type and accounted25519
indexer_queriesQuery the Aptos indexer for aggregated token, coin, and transaction dataed25519, indexer
  • 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.