Skip to main content

aptos_sdk/
lib.rs

1//! # Aptos Rust SDK v2
2//!
3//! A user-friendly, idiomatic Rust SDK for the Aptos blockchain.
4//!
5//! This SDK provides a complete interface for interacting with the Aptos blockchain,
6//! including account management, transaction building and signing, and API clients
7//! for both the fullnode REST API and the indexer GraphQL API.
8//!
9//! ## Quick Start
10//!
11//! ```rust,ignore
12//! use aptos_sdk::{Aptos, AptosConfig};
13//! use aptos_sdk::account::{Account, Ed25519Account};
14//!
15//! #[tokio::main]
16//! async fn main() -> anyhow::Result<()> {
17//!     // Connect to testnet
18//!     let aptos = Aptos::new(AptosConfig::testnet())?;
19//!
20//!     // Create a new account
21//!     let account = Ed25519Account::generate();
22//!     println!("Address: {}", account.address());
23//!
24//!     // Get balance (after funding)
25//!     let balance = aptos.get_balance(account.address()).await?;
26//!     println!("Balance: {} octas", balance);
27//!
28//!     Ok(())
29//! }
30//! ```
31//!
32//! ## Feature Flags
33//!
34//! The SDK uses feature flags to allow you to include only the functionality you need:
35//!
36//! | Feature | Default | Description |
37//! |---------|---------|-------------|
38//! | `ed25519` | Yes | Ed25519 signature scheme |
39//! | `secp256k1` | Yes | Secp256k1 ECDSA signatures |
40//! | `secp256r1` | Yes | Secp256r1 (P-256) ECDSA signatures |
41//! | `mnemonic` | Yes | BIP-39 mnemonic phrase support for key derivation |
42//! | `indexer` | Yes | GraphQL indexer client |
43//! | `faucet` | Yes | Faucet integration for testnets |
44//! | `bls` | No | BLS12-381 signatures |
45//! | `keyless` | No | OIDC-based keyless authentication |
46//! | `macros` | No | Proc macros for type-safe contract bindings |
47//!
48//! ## Modules
49//!
50//! - [`account`] - Account management and key generation
51//! - [`crypto`] - Cryptographic primitives and signature schemes
52//! - [`transaction`] - Transaction building and signing
53//! - [`api`] - REST and GraphQL API clients
54//! - [`types`] - Core Aptos types
55//! - [`codegen`] - Code generation from Move ABIs
56
57// docs.rs parity: stabilise the `doc_cfg` feature so feature-gated items
58// render as such on docs.rs. All other lint configuration now lives in
59// `[workspace.lints]` in the root `Cargo.toml`.
60#![cfg_attr(docsrs, feature(doc_cfg))]
61
62pub mod account;
63pub mod api;
64pub mod codegen;
65pub mod config;
66pub mod crypto;
67pub mod error;
68pub mod retry;
69pub mod transaction;
70pub mod types;
71
72mod aptos;
73
74// Re-export main entry points
75pub use aptos::Aptos;
76pub use config::AptosConfig;
77pub use error::{AptosError, AptosResult};
78
79// Re-export commonly used types
80pub use types::{AccountAddress, ChainId, HashValue};
81
82// Re-export proc macros when the feature is enabled
83#[cfg(feature = "macros")]
84pub use aptos_sdk_macros::{MoveStruct, aptos_contract, aptos_contract_file};
85
86// Re-export aptos_bcs for use by the MoveStruct derive macro
87// This allows downstream users to use the derive macro without adding aptos-bcs as a dependency
88#[doc(hidden)]
89pub use aptos_bcs;
90
91// Re-export const_hex for use by generated code (codegen and proc macros)
92// This allows downstream users to use generated code without adding const-hex as a dependency
93#[doc(hidden)]
94pub use const_hex;
95
96#[cfg(test)]
97mod tests;