Skip to content

Commit

Permalink
docs: add airdrop example
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfrosty committed Feb 25, 2025
1 parent 7498287 commit 2658159
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions examples/get-started/src/airdrop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
address,
lamports,
airdropFactory,
createSolanaClient,
SolanaClusterMoniker,
} from "gill";

/**
* Load a keypair signer from the local filesystem
*
* This defaults to the file path used by the Solana CLI: `~/.config/solana/id.json`
*/
const wallet = address("nick6zJc6HpW3kfBm4xS2dmbuVRyb5F3AnUvj5ymzR5");
console.log("wallet:", wallet);

/**
* Declare what Solana network cluster we want our code to interact with
*/
const cluster: SolanaClusterMoniker = "devnet";

/**
* Create a client connection to the Solana blockchain
*
* Note: `urlOrMoniker` can be either a Solana network moniker or a full URL of your RPC provider
*/
const { rpc, rpcSubscriptions } = createSolanaClient({
urlOrMoniker: cluster,
});

/**
* Get the current lamport balance of the `wallet`
*/
const { value: initialBalance } = await rpc.getBalance(wallet).send();
console.log("Initial balance:", initialBalance);

/**
* Request an airdrop of testing tokens to the `wallet` address
*
* Note: devnet and testnet are subject to rate limits.
* it is strongly recommended to use `localnet` and the local test validator
*/
await airdropFactory({ rpc, rpcSubscriptions })({
commitment: "confirmed",
lamports: lamports(100n),
recipientAddress: wallet,
});

/**
* Get the current new lamport balance of the `wallet`
*/
const { value: newBalance } = await rpc.getBalance(wallet).send();
console.log("New balance:", newBalance);

0 comments on commit 2658159

Please sign in to comment.