pub struct FaucetClient { /* private fields */ }Available on crate feature
faucet only.Expand description
Client for the Aptos faucet service.
The faucet is only available on devnet and testnet. Requests are automatically retried with exponential backoff for transient failures.
§Example
use aptos_sdk::api::FaucetClient;
use aptos_sdk::config::AptosConfig;
use aptos_sdk::types::AccountAddress;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = AptosConfig::testnet();
let client = FaucetClient::new(&config)?;
let address = AccountAddress::from_hex("0x123")?;
client.fund(address, 100_000_000).await?;
Ok(())
}Implementations§
Source§impl FaucetClient
impl FaucetClient
Sourcepub fn new(config: &AptosConfig) -> AptosResult<Self>
pub fn new(config: &AptosConfig) -> AptosResult<Self>
Creates a new faucet client.
§Errors
Returns an error if the faucet URL is not configured in the config, or if the HTTP client fails to build (e.g., invalid TLS configuration).
Sourcepub fn with_url(url: &str) -> AptosResult<Self>
pub fn with_url(url: &str) -> AptosResult<Self>
Sourcepub async fn fund(
&self,
address: AccountAddress,
amount: u64,
) -> AptosResult<Vec<String>>
pub async fn fund( &self, address: AccountAddress, amount: u64, ) -> AptosResult<Vec<String>>
Funds an account with the specified amount of octas.
§Arguments
address- The account address to fundamount- Amount in octas (1 APT = 10^8 octas)
§Returns
The transaction hashes of the funding transactions.
§Errors
Returns an error if the URL cannot be built, the HTTP request fails, the API returns an error status code (e.g., rate limiting 429, server error 500), or the response cannot be parsed as JSON.
Sourcepub async fn fund_default(
&self,
address: AccountAddress,
) -> AptosResult<Vec<String>>
pub async fn fund_default( &self, address: AccountAddress, ) -> AptosResult<Vec<String>>
Sourcepub async fn create_and_fund(
&self,
amount: u64,
) -> AptosResult<(Ed25519Account, Vec<String>)>
Available on crate feature ed25519 only.
pub async fn create_and_fund( &self, amount: u64, ) -> AptosResult<(Ed25519Account, Vec<String>)>
ed25519 only.Trait Implementations§
Source§impl Clone for FaucetClient
impl Clone for FaucetClient
Source§fn clone(&self) -> FaucetClient
fn clone(&self) -> FaucetClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FaucetClient
impl !RefUnwindSafe for FaucetClient
impl Send for FaucetClient
impl Sync for FaucetClient
impl Unpin for FaucetClient
impl !UnwindSafe for FaucetClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more