Skip to main content

FullnodeClient

Struct FullnodeClient 

Source
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

Source

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).

Source

pub fn base_url(&self) -> &Url

Returns the base URL for the fullnode.

Source

pub fn retry_config(&self) -> &RetryConfig

Returns the retry configuration.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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).

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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

Source§

fn clone(&self) -> FullnodeClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FullnodeClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more