Etherscan – How to Get Token Transfer Data of Specific Token Using API

etherscanpython

What I need

I need all information of tab "Token Transfers" in token info at etherscan. Exactly in format at the site. For example I want to get all Token Transfers from here https://etherscan.io/token/Decentraland.
And question is: How to get this data through api?

What I tried to do

  1. For local solution I got it manually downloading CSV through interface on Etherscan, but I need update data regularly and manual solution is a pain.

  2. I found this answer Obtain token transfer data from an address and it seemed to me as very useful but it didn't give me a token quantity information. Actually, it gave me transactionHash and I tried to get desired result through transactions api-methods (where is used these params module=account&action=txlist), but it didn't get me valid quantity (0.5 eth were showed like value=500000).

Moreover, I think it could be more simplier way to get this info — that's why I'm here.

A bit of code

The python code I used to get transaction info

import requests
url = 'https://api.etherscan.io/api?module=logs&action=getLogs\
&fromBlock=0\
&toBlock=latest\
&address=0x0f5d2fb29fb7d3cfee444a200298f468908cc942\
&apikey='+apikey
request = requests.get(url)
results = request.json()

Best Answer

Moreover, I think it could be more simplier way to get this info — that's why I'm here.

You're right, there is a different approach that is probably easier...

One issue is that you're approaching this from a 'legacy', centralised, fragile API mindset - all of the data that Etherscan is using; all of the data that you need is stored in Ethereum. The approach that you are taking could result in your code breaking if Etherscan charge their API, their service goes down or they decide to charge for it etc.

A better approach is to go straight to the source - Ethereum.

I want to get all Token Transfers from here

The Decentraland token is an ERC20 token; that means that we can be sure that every time that a token is transferred that the Transfer event is fired:

event Transfer(address indexed from, address indexed to, uint tokens);

There are libraries such as web3js that let you process all of these events - historically and/or using an event subscription approach.

There are even services such as Infura that can be used to access the Ethereum data (so that you don't have to run your own local node).

And documentation on how to create a web3 enabled web application using Infura.

This is how I would suggest that you approach the problem.

Related Topic