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 SOL
commitment: "confirmed"
});
const { value } = await rpc.getBalance(wallet.address).send();
console.log(`Balance: ${value / LAMPORTS_PER_SOL} SOL`);
Console
Click to execute the code.
Gill
import {
airdropFactory,
createSolanaClient,
generateKeyPairSigner,
lamports
} from "gill";
const { rpc, rpcSubscriptions } = createSolanaClient({
urlOrMoniker: "localnet"
});
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 SOL
commitment: "confirmed"
});
const { value } = await rpc.getBalance(wallet.address).send();
console.log(`Balance: ${value / LAMPORTS_PER_SOL} SOL`);

Is this page helpful?

管理者

©️ 2025 Solana 基金会版权所有
取得联系