Skip to main content

AptosConfig

Struct AptosConfig 

Source
pub struct AptosConfig { /* private fields */ }
Expand description

Configuration for the Aptos client.

Use the builder methods to customize the configuration, or use one of the preset configurations like AptosConfig::mainnet(), AptosConfig::testnet(), or AptosConfig::devnet().

§Example

use aptos_sdk::AptosConfig;
use aptos_sdk::retry::RetryConfig;
use aptos_sdk::config::PoolConfig;

// Use testnet with default settings
let config = AptosConfig::testnet();

// Custom configuration with retry and connection pooling
let config = AptosConfig::testnet()
    .with_timeout(std::time::Duration::from_secs(30))
    .with_retry(RetryConfig::aggressive())
    .with_pool(PoolConfig::high_throughput());

Implementations§

Source§

impl AptosConfig

Source

pub fn mainnet() -> Self

Creates a configuration for Aptos mainnet.

§Example
use aptos_sdk::AptosConfig;

let config = AptosConfig::mainnet();
Source

pub fn testnet() -> Self

Creates a configuration for Aptos testnet.

§Example
use aptos_sdk::AptosConfig;

let config = AptosConfig::testnet();
Source

pub fn devnet() -> Self

Creates a configuration for Aptos devnet.

§Example
use aptos_sdk::AptosConfig;

let config = AptosConfig::devnet();
Source

pub fn local() -> Self

Creates a configuration for a local development network.

This assumes the local network is running on the default ports (REST API on 8080, faucet on 8081).

§Example
use aptos_sdk::AptosConfig;

let config = AptosConfig::local();
Source

pub fn custom(fullnode_url: &str) -> AptosResult<Self>

Creates a custom configuration with the specified fullnode URL.

§Security

Only http:// and https:// URL schemes are allowed. Using https:// is strongly recommended for production. HTTP is acceptable only for localhost development environments.

§Errors

Returns an error if the fullnode_url cannot be parsed as a valid URL or uses an unsupported scheme (e.g., file://, ftp://).

§Example
use aptos_sdk::AptosConfig;

let config = AptosConfig::custom("https://my-node.example.com/v1").unwrap();
Source

pub fn with_timeout(self, timeout: Duration) -> Self

Sets the request timeout.

Source

pub fn with_retry(self, retry_config: RetryConfig) -> Self

Sets the retry configuration for transient failures.

§Example
use aptos_sdk::AptosConfig;
use aptos_sdk::retry::RetryConfig;

let config = AptosConfig::testnet()
    .with_retry(RetryConfig::aggressive());
Source

pub fn without_retry(self) -> Self

Disables automatic retry for API calls.

This is equivalent to with_retry(RetryConfig::no_retry()).

Source

pub fn with_max_retries(self, max_retries: u32) -> Self

Sets the maximum number of retries for transient failures.

This is a convenience method that modifies the retry config.

Source

pub fn with_pool(self, pool_config: PoolConfig) -> Self

Sets the connection pool configuration.

§Example
use aptos_sdk::AptosConfig;
use aptos_sdk::config::PoolConfig;

let config = AptosConfig::testnet()
    .with_pool(PoolConfig::high_throughput());
Source

pub fn with_api_key(self, api_key: impl Into<String>) -> Self

Sets an API key for authenticated access.

This is useful when using Aptos Build or other services that provide higher rate limits with API keys.

Source

pub fn with_indexer_url(self, url: &str) -> AptosResult<Self>

Sets a custom indexer URL.

§Security

Only http:// and https:// URL schemes are allowed.

§Errors

Returns an error if the url cannot be parsed as a valid URL or uses an unsupported scheme.

Source

pub fn with_faucet_url(self, url: &str) -> AptosResult<Self>

Sets a custom faucet URL.

§Security

Only http:// and https:// URL schemes are allowed.

§Errors

Returns an error if the url cannot be parsed as a valid URL or uses an unsupported scheme.

Source

pub fn network(&self) -> Network

Returns the network this config is for.

Source

pub fn fullnode_url(&self) -> &Url

Returns the fullnode URL.

Source

pub fn indexer_url(&self) -> Option<&Url>

Returns the indexer URL, if configured.

Source

pub fn faucet_url(&self) -> Option<&Url>

Returns the faucet URL, if configured.

Source

pub fn chain_id(&self) -> ChainId

Returns the chain ID for this configuration.

Source

pub fn retry_config(&self) -> &RetryConfig

Returns the retry configuration.

Source

pub fn timeout(&self) -> Duration

Returns the request timeout.

Source

pub fn pool_config(&self) -> &PoolConfig

Returns the connection pool configuration.

Trait Implementations§

Source§

impl Clone for AptosConfig

Source§

fn clone(&self) -> AptosConfig

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 AptosConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for AptosConfig

Source§

fn default() -> Self

Returns the “default value” for a type. 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