pub struct FullnodeClient { /* private fields */ }Expand description
Client for the Aptos fullnode REST API.
The client supports automatic retry with exponential backoff for transient
failures. Configure retry behavior via AptosConfig::with_retry.
§Example
use aptos_sdk::api::FullnodeClient;
use aptos_sdk::config::AptosConfig;
use aptos_sdk::retry::RetryConfig;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Default retry configuration
let client = FullnodeClient::new(AptosConfig::testnet())?;
// Aggressive retry for unstable networks
let client = FullnodeClient::new(
AptosConfig::testnet().with_retry(RetryConfig::aggressive())
)?;
// Disable retry for debugging
let client = FullnodeClient::new(
AptosConfig::testnet().without_retry()
)?;
let ledger_info = client.get_ledger_info().await?;
println!("Ledger version: {:?}", ledger_info.data.version());
Ok(())
}Implementations§
Source§impl FullnodeClient
impl FullnodeClient
Sourcepub fn new(config: AptosConfig) -> AptosResult<Self>
pub fn new(config: AptosConfig) -> AptosResult<Self>
Creates a new fullnode client.
§TLS Security
This client uses reqwest with its default TLS configuration, which:
- Validates server certificates against the system’s certificate store
- Requires valid TLS certificates for HTTPS connections
- Uses secure TLS versions (TLS 1.2+)
All Aptos network endpoints (mainnet, testnet, devnet) use HTTPS with valid certificates. The local configuration uses HTTP for development.
For custom deployments requiring custom CA certificates, use the
REQUESTS_CA_BUNDLE or SSL_CERT_FILE environment variables, or
configure a custom reqwest::Client and use from_client().
§Errors
Returns an error if the HTTP client fails to build (e.g., invalid TLS configuration).
Sourcepub fn retry_config(&self) -> &RetryConfig
pub fn retry_config(&self) -> &RetryConfig
Returns the retry configuration.
Sourcepub async fn get_ledger_info(&self) -> AptosResult<AptosResponse<LedgerInfo>>
pub async fn get_ledger_info(&self) -> AptosResult<AptosResponse<LedgerInfo>>
Gets the current ledger information.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, or the response cannot be parsed as JSON.
Sourcepub async fn get_account(
&self,
address: AccountAddress,
) -> AptosResult<AptosResponse<AccountData>>
pub async fn get_account( &self, address: AccountAddress, ) -> AptosResult<AptosResponse<AccountData>>
Gets account information.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, the response cannot be parsed as JSON, or the account is not found (404).
Sourcepub async fn get_sequence_number(
&self,
address: AccountAddress,
) -> AptosResult<u64>
pub async fn get_sequence_number( &self, address: AccountAddress, ) -> AptosResult<u64>
Gets the sequence number for an account.
§Errors
Returns an error if fetching the account fails, the account is not found (404), or the sequence number cannot be parsed from the account data.
Sourcepub async fn get_account_resources(
&self,
address: AccountAddress,
) -> AptosResult<AptosResponse<Vec<Resource>>>
pub async fn get_account_resources( &self, address: AccountAddress, ) -> AptosResult<AptosResponse<Vec<Resource>>>
Gets all resources for an account.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, or the response cannot be parsed as JSON.
Sourcepub async fn get_account_resource(
&self,
address: AccountAddress,
resource_type: &str,
) -> AptosResult<AptosResponse<Resource>>
pub async fn get_account_resource( &self, address: AccountAddress, resource_type: &str, ) -> AptosResult<AptosResponse<Resource>>
Gets a specific resource for an account.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, the response cannot be parsed as JSON, or the resource is not found (404).
Sourcepub async fn get_account_modules(
&self,
address: AccountAddress,
) -> AptosResult<AptosResponse<Vec<MoveModule>>>
pub async fn get_account_modules( &self, address: AccountAddress, ) -> AptosResult<AptosResponse<Vec<MoveModule>>>
Gets all modules for an account.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, or the response cannot be parsed as JSON.
Sourcepub async fn get_account_module(
&self,
address: AccountAddress,
module_name: &str,
) -> AptosResult<AptosResponse<MoveModule>>
pub async fn get_account_module( &self, address: AccountAddress, module_name: &str, ) -> AptosResult<AptosResponse<MoveModule>>
Gets a specific module for an account.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, the response cannot be parsed as JSON, or the module is not found (404).
Sourcepub async fn get_account_balance(
&self,
address: AccountAddress,
) -> AptosResult<u64>
pub async fn get_account_balance( &self, address: AccountAddress, ) -> AptosResult<u64>
Gets the APT balance for an account in octas.
§Errors
Returns an error if the view function call fails, the response cannot be parsed, or the balance value cannot be converted to u64.
Sourcepub async fn submit_transaction(
&self,
signed_txn: &SignedTransaction,
) -> AptosResult<AptosResponse<PendingTransaction>>
pub async fn submit_transaction( &self, signed_txn: &SignedTransaction, ) -> AptosResult<AptosResponse<PendingTransaction>>
Submits a signed transaction.
Note: Transaction submission is automatically retried for transient errors. Duplicate transaction submissions (same hash) are safe and idempotent.
§Errors
Returns an error if the transaction cannot be serialized to BCS, the HTTP request fails, the API returns an error status code, or the response cannot be parsed as JSON.
Sourcepub async fn submit_and_wait(
&self,
signed_txn: &SignedTransaction,
timeout: Option<Duration>,
) -> AptosResult<AptosResponse<Value>>
pub async fn submit_and_wait( &self, signed_txn: &SignedTransaction, timeout: Option<Duration>, ) -> AptosResult<AptosResponse<Value>>
Submits a transaction and waits for it to be committed.
§Errors
Returns an error if transaction submission fails, the transaction times out waiting for commitment, the transaction execution fails, or any HTTP/API errors occur.
Sourcepub async fn get_transaction_by_hash(
&self,
hash: &HashValue,
) -> AptosResult<AptosResponse<Value>>
pub async fn get_transaction_by_hash( &self, hash: &HashValue, ) -> AptosResult<AptosResponse<Value>>
Gets a transaction by hash.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, the response cannot be parsed as JSON, or the transaction is not found (404).
Sourcepub async fn wait_for_transaction(
&self,
hash: &HashValue,
timeout: Option<Duration>,
) -> AptosResult<AptosResponse<Value>>
pub async fn wait_for_transaction( &self, hash: &HashValue, timeout: Option<Duration>, ) -> AptosResult<AptosResponse<Value>>
Waits for a transaction to be committed.
Uses exponential backoff for polling, starting at 200ms and doubling up to 2s.
§Errors
Returns an error if the transaction times out waiting for commitment, the transaction
execution fails (vm_status indicates failure), or HTTP/API errors occur while polling.
Sourcepub async fn simulate_transaction(
&self,
signed_txn: &SignedTransaction,
) -> AptosResult<AptosResponse<Vec<Value>>>
pub async fn simulate_transaction( &self, signed_txn: &SignedTransaction, ) -> AptosResult<AptosResponse<Vec<Value>>>
Simulates a transaction.
§Errors
Returns an error if the transaction cannot be serialized to BCS, the HTTP request fails, the API returns an error status code, or the response cannot be parsed as JSON.
Sourcepub async fn estimate_gas_price(
&self,
) -> AptosResult<AptosResponse<GasEstimation>>
pub async fn estimate_gas_price( &self, ) -> AptosResult<AptosResponse<GasEstimation>>
Gets the current gas estimation.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, or the response cannot be parsed as JSON.
Sourcepub async fn view(
&self,
function: &str,
type_args: Vec<String>,
args: Vec<Value>,
) -> AptosResult<AptosResponse<Vec<Value>>>
pub async fn view( &self, function: &str, type_args: Vec<String>, args: Vec<Value>, ) -> AptosResult<AptosResponse<Vec<Value>>>
Calls a view function.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, or the response cannot be parsed as JSON.
Sourcepub async fn view_bcs(
&self,
function: &str,
type_args: Vec<String>,
args: Vec<Vec<u8>>,
) -> AptosResult<AptosResponse<Vec<u8>>>
pub async fn view_bcs( &self, function: &str, type_args: Vec<String>, args: Vec<Vec<u8>>, ) -> AptosResult<AptosResponse<Vec<u8>>>
Calls a view function using BCS encoding for both inputs and outputs.
This method provides lossless serialization by using BCS (Binary Canonical Serialization) instead of JSON, which is important for large integers (u128, u256) and other types where JSON can lose precision.
§Arguments
function- The fully qualified function name (e.g.,0x1::coin::balance)type_args- Type arguments as strings (e.g.,0x1::aptos_coin::AptosCoin)args- Pre-serialized BCS arguments as byte vectors
§Returns
Returns the raw BCS-encoded response bytes, which can be deserialized
into the expected return type using aptos_bcs::from_bytes.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, or the BCS serialization fails.
Sourcepub async fn get_events_by_event_handle(
&self,
address: AccountAddress,
event_handle_struct: &str,
field_name: &str,
start: Option<u64>,
limit: Option<u64>,
) -> AptosResult<AptosResponse<Vec<Value>>>
pub async fn get_events_by_event_handle( &self, address: AccountAddress, event_handle_struct: &str, field_name: &str, start: Option<u64>, limit: Option<u64>, ) -> AptosResult<AptosResponse<Vec<Value>>>
Gets events by event handle.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, or the response cannot be parsed as JSON.
Sourcepub async fn get_block_by_height(
&self,
height: u64,
with_transactions: bool,
) -> AptosResult<AptosResponse<Value>>
pub async fn get_block_by_height( &self, height: u64, with_transactions: bool, ) -> AptosResult<AptosResponse<Value>>
Gets block by height.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, the response cannot be parsed as JSON, or the block is not found (404).
Sourcepub async fn get_block_by_version(
&self,
version: u64,
with_transactions: bool,
) -> AptosResult<AptosResponse<Value>>
pub async fn get_block_by_version( &self, version: u64, with_transactions: bool, ) -> AptosResult<AptosResponse<Value>>
Gets block by version.
§Errors
Returns an error if the HTTP request fails, the API returns an error status code, the response cannot be parsed as JSON, or the block is not found (404).
Trait Implementations§
Source§impl Clone for FullnodeClient
impl Clone for FullnodeClient
Source§fn clone(&self) -> FullnodeClient
fn clone(&self) -> FullnodeClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more