2

Say I have an ERC20 token and I want to distribute it 1:1 to all ETH token holders at a given block. Is there a straight forward way to make a smart contract that anyone could call in order to receive their tokens?

3 Answers 3

1

What you can do is to ask the ETH holders to call a custom function in you contract (claim tokens).

Basically this function will do the following:

  1. Get the sender info (address and balance)
  2. If the address is new, send X amount of tokens according to his ETH balance.
  3. Save the address in a mapping so that he cannot claim more tokens using this function.
0

you can of course do this. Gavcoin is a very early example. The following link should help.

What are GavCoins and what is their significance?

3
  • 1
    Hmm, that looks like a pretty straight forward token implementation and nothing related to air dropping tokens based on current ETH in accounts. But half the links from the post you linked are non-functional so maybe I am missing something.
    – John Riley
    Commented Aug 24, 2017 at 16:45
  • Gavcoin was created such that any address could request Gavcoin. Presumably, this could be done many times and you'd want to restrict it to once per address in your contract. gavwood.com/gavcoin.html I don't think you'd want to air drop your token to every address on the network as the transaction fees would be enormous. Is this your plan? Querying the current balance of all Eth accounts would be best done outside of a contract as the gas required to compute this would also be enormous.
    – forgetso
    Commented Aug 25, 2017 at 10:08
  • My intent is to get a wide distribution to existing Ethereum holders. Allowing any address to request a certain amount of tokens only makes sense for a demo type coin as if the token had any kind of value, people would just create additional addresses. I guess I was wondering if it was possible to get the amount of Eth at an address at a particular block number from the past from a contract. This could also probably be done off chain as well if that is not possible.
    – John Riley
    Commented Aug 28, 2017 at 18:39
0

ERC-20 tokens do not maintain an iterable list of current token holders, the used mapping type allows you only to check for a known address - balance. To get a list of all token holders, you need to process this offline and build it yourself from blockchain data. You cannot do this in a smart contract (it is too resource heavy operation).

After you have the list of token holders, there are various tools that allow you to send airdrops to given address list.

I have created a standalone tool which collects ERC-20 token holders and transactions to SQLite database

  • Take a token contract address

  • Iterate over all Transfer events for token using eth_getLogs JSON-RPC API

  • Build a local database of these events

  • Allow you to use SQL to query any account balance on any point of time (block num)

The tool maintains a local SQLite database. The subsequent command runs scan the new blocks, since last run, and write the new transactions to the database. Exporting this from SQL based on a timestamp should be quite easy.

You can find the command line application execution example how to build the token holder database here

The core Python logic is here.

There are some quirks here and there: for example detecting mint / creation event for some tokens is not straightforward. Thus, you will may negative balance on the account receiving initial total supply if you rely on Transfer event only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.