I am own searching best way to do it because I consider the way I use is complicated a bit. But approach could be usefull for you if you don't have any solution yet. At least it works
As I know there are two ways to distinct etherium data:
If you use IPCProvider (e.g geth):
- take all transaction of your token filtering it
filter = web3.eth.filter({
'fromBlock': _min_block,
'toBlock': _max_block,
'address':ERC20address
})
tx_list = filtering.get(only_changes=False)
more about filterring here: https://web3py.readthedocs.io/en/stable/filters.html
tx_list
is the list of transactions with participating defined ERC20 — iterate it to extract addresses and timestamp (time when they made it). Note: transaction entire doesn't contain timestamp, but you can get it through timestamp of block this transaction.
raw_addresses_list = []
for tx in tx_list:
from_ = tx['topics'][1]
to_= tx['topics'][2]
raw_addresses_list.extend([from_,to_])
timestamp = web3.eth.getBlock(tx['blockHash'])['timestamp']
unique_addresses = set(raw_addresses_list)
If you use HTTPprovider (e.g infura):**
it's a bit more complicated since infura doesn't support filter method
- take all transaction of your token through iterating all blocks
for block in range(_min_block,_max_block+1)):
block_data = web3.eth.getBlock(block)
for tx in block_data['transactions']:
tx = web3.eth.getTransaction(tx)
input_ = tx['input'].split(delimeter)
from_ = tx['from']
to_ = input_ [0][10:]
timestamp = block_data['timestamp']