DEV Community 👩‍💻👨‍💻

Ycrypto-3
Ycrypto-3

Posted on

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).

Using Devnet

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
Enter fullscreen mode Exit fullscreen mode

Now time to Airdrop some sol(only possible in devnet)

$ solana airdrop 3
//Output
Requesting airdrop of 3

Signature: Transaction Signature

3 SOL
Enter fullscreen mode Exit fullscreen mode

Now check your balance

$ solana balance
//Output:
3 SOL 
Enter fullscreen mode Exit fullscreen mode

Creating a token

$ spl-token create-token
Creating token BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL
Signature: 47hsLFxWRCg8azaZZPSnQR8DNTRsGyPNfUK7jqyzgt7wf9eag3nSnewqoZrVZHKm8zt3B6gzxhr91gdQ5qYrsRG4

Enter fullscreen mode Exit fullscreen mode

Tokens when initially created by spl-token have no supply:

$ spl-token supply BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL
0
Enter fullscreen mode Exit fullscreen mode

Mint 1,000,000 tokens

$ spl-token mint BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL1000000
Minting 1000000 tokens
  Token: BiJyWQr1Gpke3ouevgGCjtd9sSwSiUxdpnpGvJaoGQNL
  Recipient: 7UX2i7SucgLMQcfZ75s3VXmZZY4YRUyJN9X1RgfMoDUi
Signature: 41mARH42fPkbYn1mvQ6hYLjmJtjW98NXwd6pHqEYg9p8RnuoUsMxVd16RkStDHEzcS2sfpSEpFscrJQn3HkHzLaa
Enter fullscreen mode Exit fullscreen mode

Now the airdrop script

First create an airdrop.txt file and input the
the wallet addresses of your supporters

GZvckYS4Dha5rkntrLkMrhRi9rgiPxhRCtJEUvTt7MJg
BQoGsMpPnz8GAazZjAYk8HJbZ2zH8rcp5s175ynMcMXo
ERG5PiNZEV6gcNJ3udxye94ahzdbesR6g8HvDFj8nGUr

Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)

Enter fullscreen mode Exit fullscreen mode

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  
Enter fullscreen mode Exit fullscreen mode

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)

Top comments (2)

Collapse
 
solreaper88 profile image
Upbring Token

Ycrypto-3 Upbring is hiring and we are Solana Based! This is something that I need done on the project. I welcome you to follow our project, we have over 4,600 followers on twitter, and 2500 in our discord. If you are interested in joining forces please contact me via our discord. Link can be found on our website upbringtoken.com. We have a huge airdrop happening currently and I have paid out of pocket for the first 1,000 addresses manually. Your inputs will be hugely appreciated! Thank you! I will be eagerly waiting for your response.

Discord: discord.gg/BSbU43Ag
Github: github.com/SOLreaper88
Twitter: twitter.com/UpbringToken
Telegram: t.me/upbringtoken
Website: upbringtoken.com
Email: upbringtoken@gmail.com

Collapse
 
cmgonsalves profile image
cmgonsalves

to create a token account automatically in the receiving wallets you should add --allow-unfunded-recipient in addition to --fund-recipient

12 APIs That You Will Love

Free and easy to use APIs for your next project, learning a new technology, or building a new feature.