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
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:
- Get the sender info (address and balance)
- If the address is new, send X amount of tokens according to his ETH balance.
- Save the address in a mapping so that he cannot claim more tokens using this function.
- 664
- 3
- 15
you can of course do this. Gavcoin is a very early example. The following link should help.
- 163
- 6
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
Transferevents for token usingeth_getLogsJSON-RPC APIBuild 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.
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.
- 22,269
- 6
- 62
- 127
http://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 Aug 25 '17 at 10:08