Rust SDK Quickstart
-
Create a Cargo project and add the SDK
The SDK requires Rust 1.95+.
Terminal window cargo new aptos-rust-quickstartcd aptos-rust-quickstartAdd dependencies to
Cargo.toml:[dependencies]aptos-sdk = "0.7"tokio = { version = "1", features = ["full"] }anyhow = "1"serde_json = "1" -
Set up the Aptos client
use aptos_sdk::{Aptos, AptosConfig};let aptos = Aptos::new(AptosConfig::devnet())?;println!("Connected to Aptos devnet"); -
Create and fund accounts
use aptos_sdk::account::Ed25519Account;let alice = Ed25519Account::generate();let bob = Ed25519Account::generate();// Default max_gas_amount is 2_000_000. Fund well above the transfer amount.aptos.fund_account(alice.address(), 1_000_000_000).await?;You can also generate and fund in one step with
aptos.create_funded_account(amount). On testnet, mint from the faucet page. -
Transfer APT
aptos.transfer_aptbuilds, signs, submits, and waits.let result = aptos.transfer_apt(&alice, bob.address(), 1_000).await?;println!("Submitted: {:?}", result.data.get("hash"));For the lower-level build → simulate → sign → submit → wait flow, see Building Transactions.
Full Quickstart Code
Section titled “Full Quickstart Code”use aptos_sdk::{Aptos, AptosConfig, account::Ed25519Account};
const FUND_AMOUNT: u64 = 1_000_000_000;const TRANSFER_AMOUNT: u64 = 1_000;
#[tokio::main]async fn main() -> anyhow::Result<()> { let aptos = Aptos::new(AptosConfig::devnet())?;
let alice = Ed25519Account::generate(); let bob = Ed25519Account::generate();
println!("=== Addresses ==="); println!("Alice: {}", alice.address()); println!("Bob: {}", bob.address());
aptos.fund_account(alice.address(), FUND_AMOUNT).await?;
println!("=== Initial Balances ==="); println!("Alice: {}", aptos.get_balance(alice.address()).await?); println!("Bob: {}", aptos.get_balance(bob.address()).await?);
let result = aptos .transfer_apt(&alice, bob.address(), TRANSFER_AMOUNT) .await?; println!("Submitted: {:?}", result.data.get("hash"));
println!("=== Final Balances ==="); println!("Alice: {}", aptos.get_balance(alice.address()).await?); println!("Bob: {}", aptos.get_balance(bob.address()).await?);
Ok(())}Run it with:
cargo runSummary
Section titled “Summary”You just learned how to transfer APT by:
- Connecting to the network with
Aptos::new. - Creating and funding accounts.
- Submitting a transfer and waiting for execution.