Easy Solana Token Airdrops: A TypeScript Guide
Sumana
Posted on August 10, 2024
Introduction:
This TypeScript tutorial simplifies Solana token distribution. Learn to effortlessly airdrop Solana tokens programmatically, making token distribution on the Solana blockchain a breeze.
Starting a Test Validator
solana-test-validator
Step 1: Setting Up Your TypeScript Project
Initialize a TypeScript project:
npm init -y
npm install --save-dev typescript
npx tsc --init
Step 2: Installing Solana Web3.js Library
Install the library:
npm install --save @solana/web3.js
Step 3: Crafting the Airdrop Functionality
Create index.ts
:
import { PublicKey, Connection, LAMPORTS_PER_SOL } from "@solana/web3.js";
export const airdrop = async (address: PublicKey | string, amount: number) => {
const publicKey = new PublicKey(address);
const connection = new Connection("http://127.0.0.1:8899", "confirmed");
const signature = await connection.requestAirdrop(publicKey, amount * LAMPORTS_PER_SOL);
await connection.confirmTransaction(signature);
}
airdrop("<public key>", 1);
Step 4: Building and Executing Your Project
Build:
npm run build
Run:
node dist/index.js
Conclusion:
You've learned to airdrop Solana tokens programmatically👩🏼💻! Explore further and leverage Solana's capabilities for innovative blockchain applications.
💖 💪 🙅 🚩
Sumana
Posted on August 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.