Skip to content

Requesting airdrop (Creating a faucet)

Create something like - https://solfaucet.com/

Hints

  • @solana/web3.js provides you with a requestAirdrop function.
  • You can get the current users public key using the useWallet hook

Screenshot 2024-08-30 at 5.40.32 PM.png

export function RequestAirdrop() {
const wallet = useWallet();
const { connection } = useConnection();
async function requestAirdrop() {
let amount = document.getElementById("amount").value;
await connection.requestAirdrop(wallet.publicKey, amount * LAMPORTS_PER_SOL);
alert("Airdropped " + amount + " SOL to " + wallet.publicKey.toBase58());
}
return <div>
<br/><br/>
<input id="amount" type="text" placeholder="Amount" />
<button onClick={requestAirdrop}>Request Airdrop</button>
</div>
}