Image for post
Image for post
Photo by Erwan Hesry on Unsplash

How To Airdrop Your First Token

Vincent Tran
Mar 9, 2018 · 10 min read

A Note On Asking For Help

When asking for help, I only have one rule: try to include as much information as possible. (E.g. the contract address, errors that appear in your terminal, your device type.) This way, we won’t need to go back and forth in the comments. Feel free to join our telegram and ask for help there. I’ll reply as soon as I have time.

Prerequisites

You need to follow Moritz Neto’s tutorial on how to deploy your own contract.

What You Will Learn Today

  1. You will learn the basics of how to navigate on the command line.
  2. You will learn the basics of how to fork and clone repositories on Github.
  3. You will learn how to install Nodejs through a version manager called NVM.
  4. You will learn how to use Parity (A Rust implementation of geth) to extract account balances from the Ethereum blockchain.
  5. You will learn how to run Parity so that you can broadcast transactions locally from your computer.
  6. You will learn about token decimal size, which appears in every contract.
  7. You will (finally!) learn about how to prepare the airdropping script to airdrop tokens for you.
  8. You will also learn how you can implement your own custom airdropping function so you can determine how many tokens each user should be airdropped.

Step I: Navigating The Command Line.

Whip open a terminal and start by typing in:

pwd
mkdir "cool-folder-name-here" 
cd "cool-folder-name-here"

Step II: Forking & Cloning.

Now that we have our terminal ready, we need to get the code onto our computers. This process is called cloning. Since we might make changes to the code, it is better to clone a fork of the code than the codebase itself. Forking allows us to make modifications to the code without affecting the original repository.

Image for post
Image for post
Learning to fork…
Image for post
Image for post
git clone "paste-the-url-here"
cd Airdropper

Step III: Installing Nodejs.

This airdropping script runs on Nodejs, which I recommend you install by going through Node Version Manager. The reason we will install Nodejs using NVM as opposed to any other way is because it allows for more sustainable development. NVM allows you to have fine grain control on which node version you are using, which is helpful if you are working on projects with many different node versions as dependencies.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
nvm install node

Step IV: Exporting Account Balances

To be able to successfully airdrop our awesome token to others, we must first get a list of all the addresses that we wish to airdrop to. The easiest way to achieve this is by using Parity’s export state function.

parity -pruning=archive -fat-db=on -chain=ropsten
  1. We want balances above 1 000 RtETH
  2. We want balances below 500 000 RtETH
parity export state --chain=ropsten -no-storage -no-code -min-balance=1000 -max-balance=500000 -at=2000000 balances.json

Step V: Broadcasting Transactions

Broadcasting transactions to the Ethereum network can be done in two ways via a remote node such as Infura or via a local parity mode. Since we will be broadcasting many transactions, it is better to use your own node. If you have synced your parity node using fat-db and with archive mode on, it is syncing much slower than it would if it was in fast mode. To reset your node and get it to warp sync back to the latest state, you can kill the database and then start it up again using the following commands.

parity db kill -chain=ropsten
parity -chain=ropsten -pruning=fast -fat-db=off

Step VI: Token Decimal Size

Before we get into configuring the Airdropper, I’ll talk a bit about the decimals field in the token contract. The decimals field basically describes how divisible your token will be. The reason this is important is because not all tokens should be divisible (e.g. do you want a divisible “unicorn” token?). The default value for decimals is 18. The impact of the decimals field is that all token values have to take this into account (i.e. have an extra 18 zeroes).

Step VII: Preparing The Airdropper

Let’s set up the airdropper now. The main file is in index.js. Let’s take a look at lines 18–23, which contain a few variables that we can modify. We will start off by doing a very basic airdrop of 1 token to each user.

AIRDROP_QTY refers to the fixed amount of tokens you are dropping to each user. The default value is set at 1.
DURATION is the time in between transaction submissions.
GAS_LIMIT & GAS_PRICE are the respective limits and prices that you are willing to pay for your transaction. You can check to see how many pending transactions there are on etherscan before you estimate how much gas you are willing to pay per transaction. The default value that I have left it at is 5gwei.
module.exports = {
privateKey: ‘put-your-private-key-here’,
contractAddress: ‘put-your-deployed-contract-address-here’,
abi: ‘put-your-deployed-contract-abi-here’
}

Airdrop Checklist

  1. Fully synced parity node. (You can check what block you are up to and compare it with etherscan).
  2. Enough RtETHs on your account with the tokens. You can get more from our faucet. As a ballpark estimate, 3000 transactions at 5gwei each will cost about 0.5 RtETHs (so make sure you have enough!)
  3. Your account page open on etherscan (on ropsten!) so you can see the pending transactions being broadcast to the ethereum network.
node index.js

Step VIII: Custom Airdrop Function

In practice, you don’t just want everyone to have one token. Maybe you have a cool idea about how the tokens should be distributed. For example, maybe you think that users should be rewarded tokens proportionally based on the amount of RtETHs they have. For example, if there are only two users that you wish to airdrop to and one owns 10% of the total RtETH and the other owns 90% of the RtETH, then they should receive 10% of the tokens and 90% of the tokens, respectively.

Image for post
Image for post
Custom Airdrop Function
Image for post
Image for post
Fairly Distributed Tokens.

Conclusion

Well, that’s it! By now you will have learnt how to deploy your first contract AND distribute its tokens in an equitable way. Was anything unclear in this tutorial? Got questions about how to deploy it? Let me know in the comments!

bitfwd

We bring you workshops, open-source projects and blog to…

Vincent Tran

Written by

Blockchain Consulting/Education. Head of Tech @ bitfwd. Community first, always. I aim for short, punchy pieces.

bitfwd

bitfwd

We bring you workshops, open-source projects and blog to take you where the bit is going

Vincent Tran

Written by

Blockchain Consulting/Education. Head of Tech @ bitfwd. Community first, always. I aim for short, punchy pieces.

bitfwd

bitfwd

We bring you workshops, open-source projects and blog to take you where the bit is going

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store