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
65// Install the `ring` crypto provider for `rustls` when the SDK is built with
66// the `rustls-no-provider` reqwest backend. This makes HTTPS clients work on
67// both native targets and `wasm32-unknown-unknown` without callers needing to
68// initialise the provider themselves. The provider is only installed if no
69// default has already been set (e.g. by an application that prefers
70// `aws-lc-rs`).
71#[cfg(not(target_arch = "wasm32"))]
72mod rustls_provider {
73 use rustls::crypto::CryptoProvider;
74
75 /// Installs `ring` as the default `rustls` crypto provider if none is set.
76 pub(crate) fn install_default() {
77 if CryptoProvider::get_default().is_none() {
78 let _ = rustls::crypto::ring::default_provider().install_default();
79 }
80 }
81}
82
83pub mod account;
84pub mod api;
85pub mod codegen;
86pub mod config;
87pub mod crypto;
88pub mod error;
89pub mod retry;
90pub mod transaction;
91pub mod types;
92
93mod aptos;
94
95// Re-export main entry points
96pub use aptos::Aptos;
97pub use config::AptosConfig;
98pub use error::{AptosError, AptosResult};
99
100// Re-export commonly used types
101pub use types::{AccountAddress, ChainId, HashValue};
102
103// Re-export proc macros when the feature is enabled
104#[cfg(feature = "macros")]
105pub use aptos_sdk_macros::{MoveStruct, aptos_contract, aptos_contract_file};
106
107// Re-export aptos_bcs for use by the MoveStruct derive macro
108// This allows downstream users to use the derive macro without adding aptos-bcs as a dependency
109#[doc(hidden)]
110pub use aptos_bcs;
111
112// Re-export const_hex for use by generated code (codegen and proc macros)
113// This allows downstream users to use generated code without adding const-hex as a dependency
114#[doc(hidden)]
115pub use const_hex;
116
117#[cfg(test)]
118mod tests;