[Ethereum] How to get quantity of token that an ERC20 Token has raised

etherscantokens

I'm looking to get the value raised by different ERC20 tokens (https://icodrops.com/) this site shows the amount raised. How can I get this data through an API?

I tried using Etherscan.io and Ethplorer.io but it seems to provide no data like this specifically and I can get logs data which will have to be summed up. Is there any other way?

Best Answer

The problem we are having here is that Token contract, in most cases, is not a contract which is selling Tokens. If you check ERC20 Standard https://en.wikipedia.org/wiki/ERC20 here then you will see there is no function to receive funds.

For this reason developers create Crowdsale contracts which own some amount of tokens ready to be sold and implement default payable fallback functions to receive ETH and send tokens back.

So to check what is value raised by each token you have to:

  1. Get list of all token owners from ERC20 Token contract. You can check it by getting list of all Transfer transaction. ERC20 Standard has an event

    Transfer(address indexed _from, address indexed _to, uint256 _value). [Triggered when tokens are transferred.]

    You have to filter blockchain for such events for your token contract.

  2. For each token holder you have to get list of transactions where ETH was send to this contract.

  3. For each such transaction you have to check if Token Contract was called to transfer token to account address who send money to your selling token holder.

    It is possible that sale contract received money, but did not transfer tokens back. I think we should not count such transaction as the one raising ETH for token

It is not as easy as it may look like. There is no one function which will tell you what is the amount raised by each token contract. It requires a bit of work and filtering by events and contract transactions. It is however doable.

Related Topic