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
except KeyError:
raise Exception("Airdrop response did not contain a transaction signature.")
except RPCException as e:
raise Exception(f"Faucet request failed: {str(e)}")
except Exception as e:
raise Exception(f"An error occurred: {str(e)}")
Key Features
Development-Only
Designed specifically for Solana’s devnet/testnet environments.
Quick SOL Access
Instantly funds wallets with 5 SOL for development and testing purposes.
Error Resilience
Handles missing transaction signatures, RPC issues, and unexpected errors gracefully.
Transaction Confirmation
Ensures that funds are credited by confirming the transaction after the request.
Last updated