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//! | `macros` | No | Proc macros for type-safe contract bindings |
46//! | `cli` | No | Enables the `aptos-codegen` binary for Move ABI codegen |
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//! - [`config`] - Network and client configuration ([`AptosConfig`])
57//! - [`error`] - Error types ([`AptosError`], [`AptosResult`])
58//! - [`retry`] - Retry / backoff configuration for network requests
59
60// docs.rs parity: stabilise the `doc_cfg` feature so feature-gated items
61// render as such on docs.rs. All other lint configuration now lives in
62// `[workspace.lints]` in the root `Cargo.toml`.
63#![cfg_attr(docsrs, feature(doc_cfg))]
64
65pub mod account;
66pub mod api;
67pub mod codegen;
68pub mod config;
69pub mod crypto;
70pub mod error;
71pub mod retry;
72pub mod transaction;
73pub mod types;
74
75mod aptos;
76
77// Re-export main entry points
78pub use aptos::Aptos;
79pub use config::AptosConfig;
80pub use error::{AptosError, AptosResult};
81
82// Re-export commonly used types
83pub use types::{AccountAddress, ChainId, HashValue};
84
85// Re-export proc macros when the feature is enabled
86#[cfg(feature = "macros")]
87pub use aptos_sdk_macros::{MoveStruct, aptos_contract, aptos_contract_file};
88
89// Re-export aptos_bcs for use by the MoveStruct derive macro
90// This allows downstream users to use the derive macro without adding aptos-bcs as a dependency
91#[doc(hidden)]
92pub use aptos_bcs;
93
94// Re-export const_hex for use by generated code (codegen and proc macros)
95// This allows downstream users to use generated code without adding const-hex as a dependency
96#[doc(hidden)]
97pub use const_hex;
98
99#[cfg(test)]
100mod tests;