How to airdrop SPL-tokens to hundreds of addresses
So you just created a new token and you want to airdrop them to early supporters, but let's say you have a lot of people to send the token to, trust me, it'll take a long while to send the token to all those people, so let's automate that!
First lets go through a quick guide on how to create spl tokens.
You can read the spl docs here
First make sure rust is installed(remember to restart your system after the installation).
Install the spl token cli (Command line interface)
$ cargo install spl-token-cli
To use the devnet you'll have set the solana url to the devnet with
$ solana config set --url https://api.devnet.solana.com
Now, let's create a devnet wallet:
$ solana-keygen new --outfile ~/.config/solana/devnet.json
The json file can be named whatever you want it to be
Make sure to remember to store your seed phrase somewhere secure.
Set your keypair to your new wallet
$ solana config set --keypair ~/.config/solana/devnet.json
check to make sure you're on the devnet
$ solana config get //Output: Config File: /Users/User/.config/solana/cli/config.yml RPC URL: https://api.devnet.solana.com WebSocket URL: wss://api.devnet.solana.com/ (computed) Keypair Path: /Users/User/.config/solana/devnet.json Commitment: confirmed
Now time to Airdrop some sol(only possible in devnet)
$ solana airdrop 3 //Output Requesting airdrop of 3 Signature: Transaction Signature 3 SOL
Now check your balance
$ solana balance //Output: 3 SOL
$ spl-token create-token Creating token BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL Signature: 47hsLFxWRCg8azaZZPSnQR8DNTRsGyPNfUK7jqyzgt7wf9eag3nSnewqoZrVZHKm8zt3B6gzxhr91gdQ5qYrsRG4
Tokens when initially created by spl-token have no supply:
$ spl-token supply BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL 0
Mint 1,000,000 tokens
$ spl-token mint BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL1000000 Minting 1000000 tokens Token: BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL Recipient: 7UX2i7SucgLMQcfZ75s3VXmZZY4YRUyJN9X1RgfMoDUi Signature: 41mARH42fPkbYn1mvQ6hYLjmJtjW98NXwd6pHqEYg9p8RnuoUsMxVd16RkStDHEzcS2sfpSEpFscrJQn3HkHzLaa
First create an airdrop.txt file and input the
the wallet addresses of your supporters
GZvckYS4Dha5rkntrLkMrhRi9rgiPxhRCtJEUvTt7MJg BQoGsMpPnz8GAazZjAYk8HJbZ2zH8rcp5s175ynMcMXo ERG5PiNZEV6gcNJ3udxye94ahzdbesR6g8HvDFj8nGUr
Now the Airdrop script, create a python file airdrop.py,
this will airdrop 10000 tokens to all addresses on the airdrop list
import subprocess with open('airdrop.txt', 'r+') as f: #r+ does the work of rw lines = f.readlines() for i, line in enumerate(lines): list_files = subprocess.Popen(["spl-token", "transfer", BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL", "10000",lines[i].strip()], ) list_files.wait() f.seek(0) for line in lines: f.write(line) print(line)
Now to send the airdrop it'll actually cost you some sol if you fund the wallets of your supporters, if you want to spend sol funding the wallet use this script
import subprocess with open('airdrop.txt', 'r+') as f: #r+ does the work of rw lines = f.readlines() for i, line in enumerate(lines): list_files = subprocess.Popen(["spl-token", "transfer", "--fund-recipient", BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL", "300000",lines[i].strip()], ) list_files.wait() f.seek(0) for line in lines: f.write(line) print(line)
The --fund-recipient is to create a token address associated with your token for a specific sol address, so before airdropping you can make sure your supporters have minted the token on their wallets unless they won't receive it unless you choose to fund their wallet.
Check if the addresses received their tokens
$ spl-token accounts BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL -v Account Token Balance -------------------------------------------------------------------------------------------------------- GZvckYS4Dha5rkntrLkMrhRi9rgiPxhRCtJEUvTt7MJg BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL 10000 BQoGsMpPnz8GAazZjAYk8HJbZ2zH8rcp5s175ynMcMXo BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL 10000
If an address is not on the list it means they did not mint the token address and you'll have to fund their wallet or they have to mint the token id.
I'll soon release a tutorial on how to use a Gumdrop to distribute tokens, so that your supporters pay before claiming their airdrops!
To use the mainnet-beta and take it live follow the tutorial again but replace devnet with mainnet-beta (Remember you can't airdrop sol on mainnet)