Requesting airdrop (Creating a faucet)
Create something like - https://solfaucet.com/
Hints
@solana/web3.js
provides you with arequestAirdrop
function.- You can get the
current users
public key using theuseWallet
hook
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>}