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//! ## Keyless accounts
49//!
50//! Keyless (OIDC) accounts are available behind the `keyless` feature. Users
51//! authenticate with an identity provider (Google, Apple, etc.) and the SDK
52//! derives a stable address from the JWT. See [`account::KeylessAccount`] and
53//! the [`account::keyless`] module for the full flow, pepper / prover service
54//! URLs, and a signing example. The `keyless_account` example under
55//! `examples/` demonstrates end-to-end usage when a JWT is supplied via the
56//! `APTOS_KEYLESS_JWT` environment variable.
57//!
58//! ## Modules
59//!
60//! - [`account`] - Account management and key generation
61//! - [`crypto`] - Cryptographic primitives and signature schemes
62//! - [`transaction`] - Transaction building and signing
63//! - [`api`] - REST and GraphQL API clients
64//! - [`types`] - Core Aptos types
65//! - [`codegen`] - Code generation from Move ABIs
66
67// docs.rs parity: stabilise the `doc_cfg` feature so feature-gated items
68// render as such on docs.rs. All other lint configuration now lives in
69// `[workspace.lints]` in the root `Cargo.toml`.
70#![cfg_attr(docsrs, feature(doc_cfg))]
71
72pub mod account;
73pub mod api;
74pub mod codegen;
75pub mod config;
76pub mod crypto;
77pub mod error;
78pub mod retry;
79pub mod transaction;
80pub mod types;
81
82mod aptos;
83
84// Re-export main entry points
85pub use aptos::Aptos;
86pub use config::AptosConfig;
87pub use error::{AptosError, AptosResult};
88
89// Re-export commonly used types
90pub use types::{AccountAddress, ChainId, HashValue};
91
92// Re-export proc macros when the feature is enabled
93#[cfg(feature = "macros")]
94pub use aptos_sdk_macros::{MoveStruct, aptos_contract, aptos_contract_file};
95
96// Re-export aptos_bcs for use by the MoveStruct derive macro
97// This allows downstream users to use the derive macro without adding aptos-bcs as a dependency
98#[doc(hidden)]
99pub use aptos_bcs;
100
101// Re-export const_hex for use by generated code (codegen and proc macros)
102// This allows downstream users to use generated code without adding const-hex as a dependency
103#[doc(hidden)]
104pub use const_hex;
105
106#[cfg(test)]
107mod tests;