Skip to content

Instantly share code, notes, and snippets.

@99darwin
Created May 29, 2025 19:34
Show Gist options
  • Select an option

  • Save 99darwin/bbcad52c39a6d57ebb686ff7cd97e868 to your computer and use it in GitHub Desktop.

Select an option

Save 99darwin/bbcad52c39a6d57ebb686ff7cd97e868 to your computer and use it in GitHub Desktop.
Delegate compressed airdrop to farcaster
import { approve, getOrCreateAssociatedTokenAccount } from '@solana/spl-token';
import { PublicKey, Keypair, Connection } from '@solana/web3.js';
import { createTokenPool } from '@lightprotocol/compressed-token';
import bs58 from 'bs58';
import { createRpc } from '@lightprotocol/stateless.js';
// Constants
const SOLANA_RPC_URL = 'https://staked.helius-rpc.com?api-key=<YOUR_API_KEY>'; // Replace with your preferred rpc provider
const TOKEN_MINT_ADDRESS = new PublicKey(
'YOUR_TOKEN_MINT_ADDRESS'
);
const DELEGATE_ADDRESS = new PublicKey(
'9WxWzFuaARat5ZyAu5GKazDH1eqdXhGZycfnSNPptrR2'
);
const RAW_AMOUNT = 15_000_000 * 1e6; // Replace with your airdrop amount + token decimals
// Configs
const devWallet = Keypair.fromSecretKey(
new Uint8Array(bs58.decode(process.env.YOUR_PRIVATE_KEY))
);
const connection = new Connection(SOLANA_RPC_URL, 'confirmed');
const rpc = createRpc(SOLANA_RPC_URL, SOLANA_RPC_URL, SOLANA_RPC_URL);
const main = async () => {
// Create ATA for delegate wallet
const delegateAta = await getOrCreateAssociatedTokenAccount(
connection,
devWallet,
TOKEN_MINT_ADDRESS,
DELEGATE_ADDRESS,
true
);
if (!delegateAta) {
throw new Error('Failed to create ATA');
}
// Get ata for dev wallet
const ataDevWallet = await getOrCreateAssociatedTokenAccount(
connection,
devWallet,
TOKEN_MINT_ADDRESS,
devWallet.publicKey,
true
);
if (!ataDevWallet) {
throw new Error('Failed to create ATA for dev wallet');
}
// Create compressed token pool
const poolTx = await createTokenPool(
rpc,
devWallet,
TOKEN_MINT_ADDRESS
);
console.log(poolTx);
// Approve delegate wallet
const approveIx = await approve(
connection,
devWallet,
ataDevWallet.address,
DELEGATE_ADDRESS,
devWallet,
RAW_AMOUNT
);
console.log(approveIx);
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment