Aptos Rust SDK v2
A user-friendly, idiomatic Rust SDK for the Aptos blockchain with feature parity to the TypeScript SDK.
Features
- 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, multi-sig, and keyless (OIDC) accounts
- Type Safety: Strong Rust type system for Move contract interactions
- Modular Design: Feature flags to include only what you need
Quick Start
Add to your Cargo.toml:
[]
= "0.3"
Basic usage:
use ;
use ;
async
Feature Flags
| 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 | |
keyless |
OIDC-based keyless authentication | |
macros |
Procedural macros for type-safe contract bindings | |
full |
Enable all features |
Minimal Build
For the smallest possible binary:
[]
= { = "0.1", = false, = ["ed25519"] }
Full Build
For all features:
[]
= { = "0.1", = ["full"] }
Examples
See the examples/ directory for complete working examples:
Basic Operations
transfer.rs- Basic APT transferview_function.rs- Read-only view function callstransaction_data.rs- Working with transaction data
Advanced Transactions
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
Account Types
multi_key_account.rs- Multi-key (mixed signature) accountsmulti_sig_account.rs- MultiEd25519 threshold accountsmultisig_v2.rs- On-chain multisig (governance) accounts
Smart Contracts
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
Development
Building
# Build with default features
# Build with all features
# Build with specific features only
# Check compilation (faster than build)
# Release build (optimized)
Linting
# Run clippy lints
# Check formatting
# Format code
Testing
Unit Tests
# Run unit tests with default features
# Run tests with all features
# Run tests with specific features
# Run a specific test by name
# Run tests with output visible
# Run doc tests only
# Run library tests only (no integration tests)
E2E Tests
E2E tests require a running Aptos localnet:
# Terminal 1: Start localnet
# Terminal 2: Run E2E tests
Behavioral Tests
The SDK includes Gherkin-based behavioral specification tests:
# Run behavioral tests (from workspace root)
# Run with verbose output
Code Coverage
# Unit tests only (default)
# Include E2E tests (requires localnet)
# Or use the helper script
See tarpaulin.toml for coverage configuration profiles.
Generating Documentation
# Generate and open documentation
# Generate docs without opening browser
# Include private items in docs
Resources
License
Apache-2.0