Solana CookbookDevelopment
Getting Test SOL
To send transactions while developing locally or on devnet, you'll need SOL.
You can fund an address by requesting an airdrop. If on devnet, you can use the faucet.
import {airdropFactory,createSolanaRpc,createSolanaRpcSubscriptions,generateKeyPairSigner,lamports} from "@solana/kit";const rpc = createSolanaRpc("http://localhost:8899");const rpcSubscriptions = createSolanaRpcSubscriptions("ws://localhost:8900");const wallet = await generateKeyPairSigner();const LAMPORTS_PER_SOL = 1_000_000_000n;await airdropFactory({ rpc, rpcSubscriptions })({recipientAddress: wallet.address,lamports: lamports(LAMPORTS_PER_SOL), // 1 SOLcommitment: "confirmed"});const { value } = await rpc.getBalance(wallet.address).send();console.log(`Balance: ${value / LAMPORTS_PER_SOL} SOL`);
ConsolePowered by Mirror
Click to execute the code.
Is this page helpful?