This is an example where the created wallet is not persisted by default. For more details, see the Wallet API documentation.
Copy
Ask AI
// Create a faucet request and return the transaction */const faucetTransaction = await wallet.faucet();// Wait for the faucet transaction to land onchain */await faucetTransaction.wait();console.log(`Faucet transaction successfully completed: ${faucetTransaction}`);console.log("Transaction hash:", faucetTransaction.getTransactionHash());// Check wallet balance console.log("Wallet balance after ETH faucet request:", await wallet.listBalances());
After running this example, you should see output similar to the following:
You can also bring your own wallet to claim faucet funds. Try the following to use an external address.
First, use your address to create an external address object, then wait for the faucet request to land onchain.
Copy
Ask AI
// Create external address object for your walletlet externalAddress = new ExternalAddress("base-sepolia", "0x...");// Check wallet balanceconsole.log("ETH balance before request:", await externalAddress.getBalance("eth"));// Create faucet request and wait for it to land onchainconst faucetTransactionExternal = await externalAddress.faucet("eth");faucetTransactionExternal.wait();
Your transaction may take some time to complete. You can monitor it by checking its status:
Copy
Ask AI
while (true) { const status = await faucetTransactionExternal.getStatus(); console.log("Current Transaction Status:", status); // Check if complete if (status === "complete") { console.log("\nFaucet Transaction successfully completed:"); console.log(faucetTransactionExternal); break; } // Wait for 30 seconds before rechecking console.log("Transaction is not yet complete..."); await new Promise(resolve => setTimeout(resolve, 30000)); }// Check balance console.log("ETH balance after claim:", await externalAddress.getBalance("eth"));
After running this example, you should see output similar to the following: