Request Faucet Funds

Effortlessly obtain SOL from the Solana faucet for development and testing purposes on devnet or testnet environments using the FaucetManager class.

Code Breakdown

1. Request SOL Airdrop

Send an airdrop request to the Solana faucet for a specified wallet:

Copy

response = await agent.connection.request_airdrop(  
    agent.wallet_address, 5 * LAMPORTS_PER_SOL  
)  
  • Amount: 5 SOL (adjustable).

  • Network: Devnet/Testnet only.

2. Confirm Transaction

Once the faucet provides SOL, confirm the transaction to ensure successful completion:

Copy

latest_blockhash = await agent.connection.get_latest_blockhash()  
await agent.connection.confirm_transaction(  
    tx_signature,  
    commitment=Confirmed,  
    last_valid_block_height=latest_blockhash.value.last_valid_block_height  
)  

3. Error Handling

Capture and handle potential errors during the airdrop process:

Copy


Key Features

  1. Development-Only

    • Designed specifically for Solana’s devnet/testnet environments.

  2. Quick SOL Access

    • Instantly funds wallets with 5 SOL for development and testing purposes.

  3. Error Resilience

    • Handles missing transaction signatures, RPC issues, and unexpected errors gracefully.

  4. Transaction Confirmation

    • Ensures that funds are credited by confirming the transaction after the request.

Last updated