Skip to content

Rust SDK Quickstart

  1. Create a Cargo project and add the SDK

    The SDK requires Rust 1.95+.

    Terminal window
    cargo new aptos-rust-quickstart
    cd aptos-rust-quickstart

    Add dependencies to Cargo.toml:

    [dependencies]
    aptos-sdk = "0.7"
    tokio = { version = "1", features = ["full"] }
    anyhow = "1"
    serde_json = "1"
  2. Set up the Aptos client

    use aptos_sdk::{Aptos, AptosConfig};
    let aptos = Aptos::new(AptosConfig::devnet())?;
    println!("Connected to Aptos devnet");
  3. 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.

  4. Transfer APT

    aptos.transfer_apt builds, 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.

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:

Terminal window
cargo run

You just learned how to transfer APT by:

  1. Connecting to the network with Aptos::new.
  2. Creating and funding accounts.
  3. Submitting a transfer and waiting for execution.