A user-friendly, idiomatic Rust SDK for the Aptos blockchain with feature parity to the TypeScript SDK.
- Full Blockchain Interaction: Connect, explore, and interact with the Aptos blockchain
- Multiple Signature Schemes: Ed25519, Secp256k1, Secp256r1 (P-256), and BLS12-381
- Transaction Building: Fluent builder pattern for constructing transactions
- Account Management: Single-key and multi-sig accounts
- Type Safety: Strong Rust type system for Move contract interactions
- Modular Design: Feature flags to include only what you need
Add to your Cargo.toml:
[dependencies]
aptos-sdk = "0.6.0"Basic usage:
use aptos_sdk::{Aptos, AptosConfig};
use aptos_sdk::account::{Account, Ed25519Account};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Connect to testnet
let aptos = Aptos::new(AptosConfig::testnet())?;
// Create a new account
let account = Ed25519Account::generate();
println!("Address: {}", account.address());
// Check balance
let balance = aptos.get_balance(account.address()).await?;
println!("Balance: {} octas", balance);
Ok(())
}| Feature | Default | Description |
|---|---|---|
ed25519 |
✓ | Ed25519 signature scheme |
secp256k1 |
✓ | Secp256k1 ECDSA signatures |
secp256r1 |
✓ | Secp256r1 (P-256) ECDSA signatures |
mnemonic |
✓ | BIP-39 mnemonic phrase support for key derivation |
indexer |
✓ | GraphQL indexer client |
faucet |
✓ | Faucet integration for testnets |
bls |
BLS12-381 signatures | |
macros |
Procedural macros for type-safe contract bindings | |
full |
Enable all features |
For the smallest possible binary:
[dependencies]
aptos-sdk = { version = "0.6.0", default-features = false, features = ["ed25519"] }For all features:
[dependencies]
aptos-sdk = { version = "0.6.0", features = ["full"] }See the examples/ directory for complete working examples:
transfer.rs- Basic APT transferview_function.rs- Read-only view function callstransaction_data.rs- Working with transaction data
entry_function.rs- Entry function transaction buildingscript_transaction.rs- Script-based transactionssponsored_transaction.rs- Fee payer (sponsored) transactionsmulti_agent.rs- Multi-signer transactionstransaction_waiting.rs- Transaction waiting strategiesadvanced_transactions.rs- Complex transaction combinations
multi_key_account.rs- Multi-key (mixed signature) accountsmulti_sig_account.rs- MultiEd25519 threshold accountsmultisig_v2.rs- On-chain multisig (governance) accounts
deploy_module.rs- Deploy a Move modulecall_contract.rs- Call contract entry functionsread_contract_state.rs- Read contract statenft_operations.rs- NFT/Digital Asset interactionscodegen.rs- Contract binding generationcontract_bindings.rs- Using generated type-safe bindings
# Build with default features
cargo build -p aptos-sdk
# Build with all features
cargo build -p aptos-sdk --all-features
# Build with specific features only
cargo build -p aptos-sdk --features "ed25519,secp256r1,bls"
# Check compilation (faster than build)
cargo check -p aptos-sdk --all-features
# Release build (optimized)
cargo build -p aptos-sdk --release --all-features# Run clippy lints
cargo clippy -p aptos-sdk --all-features -- -D warnings
# Check formatting
cargo fmt -p aptos-sdk -- --check
# Format code
cargo fmt -p aptos-sdk# Run unit tests with default features
cargo test -p aptos-sdk
# Run tests with all features
cargo test -p aptos-sdk --all-features
# Run tests with specific features
cargo test -p aptos-sdk --features "full"
# Run a specific test by name
cargo test -p aptos-sdk test_name
# Run tests with output visible
cargo test -p aptos-sdk -- --nocapture
# Run doc tests only
cargo test -p aptos-sdk --doc
# Run library tests only (no integration tests)
cargo test -p aptos-sdk --libE2E tests require a running Aptos localnet:
# Terminal 1: Start localnet
aptos node run-localnet
# Terminal 2: Run E2E tests
cargo test -p aptos-sdk --features "e2e" -- --ignoredThe SDK includes Gherkin-based behavioral specification tests:
# Run behavioral tests (from workspace root)
cd specifications/tests/rust
cargo test
# Run with verbose output
cargo test -- --nocapture# Unit tests only (default)
cargo tarpaulin -p aptos-sdk --features "full" --skip-clean
# Include E2E tests (requires localnet)
cargo tarpaulin -p aptos-sdk --features "full,e2e" --ignored --skip-clean --timeout 300
# Or use the helper script
./scripts/coverage.sh # Unit tests only
./scripts/coverage.sh e2e # Include E2E tests
./scripts/coverage.sh ci # CI mode with HTML/XML outputSee tarpaulin.toml for coverage configuration profiles.
# Generate and open documentation
cargo doc -p aptos-sdk --all-features --open
# Generate docs without opening browser
cargo doc -p aptos-sdk --all-features
# Include private items in docs
cargo doc -p aptos-sdk --all-features --document-private-itemsApache-2.0