0

This link shows the latest 500k transactions, and by clicking each one it opens a page with its info including gaslimit, gasprice, usedgas etc.

https://etherscan.io/txs

How can i retrieve the information for all the 500k in an automatic way, because it is tedious and not practical to do so manually.

3
  • Etherscan offers a proxy API to the underlying node. The tx receipt will give you the info you listed: etherscan.io/apis#proxy Oct 12, 2018 at 14:36
  • Note that the API is rate limited to 5 requests/second. If you genuinely need the details of all 500k transactions then it'll take you nearly 28 hours of hammering their API... (That's after you somehow get a list of the transactions to feed into the API.) Oct 12, 2018 at 14:41
  • Thanks for your replay; not realy understand how it works e.g., could you show an example to retrieve the first 1k transactions? I would appreciate that
    – MWH
    Oct 12, 2018 at 14:44

1 Answer 1

1

The API from etherscan do not have methods to get a list of the last N transactions. The solution is to download the blocks (with the transactions) and read the data from them.

Assuming an average of 250 transactions per block (source: https://bitinfocharts.com/ethereum/) having 5 requests per second, you will get the data in a couple of hours.

This can be easily done with python and you can use these tools:

https://github.com/corpetty/py-etherscan-api

or

https://github.com/jfdelgad/etherscanAPI in this last one you can just do:

from etherscanAPI import etherscan

apikey = 'yourAPIkey'
myapi = etherscan(apikey, 'mainnet')

currentblock = myapi.getBlockNumber()
txlist = []
i = 0
txcount = 0;
while txcount < 1000:
    block = myapi.getBlockByNumber(int(currentblock,16)-i)
    txlist.append(block['transactions'])
    txcount = txcount + len(block['transactions'])
    i = i + 1
    print(txcount)

txlist = [i for sublist in txlist for i in sublist]

then txlist will be a list of dictionaries containing all the data of last (>) 1000 transactions.

for instance, txlis[0] will have a dictionary:

{'blockHash': '0x60265fe6cffcbd2dc5f3872c4eb151e17919296270210985df3ef2249d99171c',
 'blockNumber': '0x63973b',
 'from': '0x5e032243d507c743b061ef021e2ec7fcc6d3ab89',
 'gas': '0xafc8',
 'gasPrice': '0xcce416600',
 'hash': '0x940cdd338b4ec8f9b2b63c01a88683f8658f9a388d79873c6bb913b34e579dd8',
 'input': '0x',
 'nonce': '0x193dd',
 'r': '0xcffe406e06ac7f5049798785d1ead4d9420aa763838592e275b997d6efb411d7',
 's': '0x5db6e46eae1dae407b4e54c49e50ccb17a41a6569cb848aae021f06d4d7fb450',
 'to': '0xf67fa6500b490a05c29a47b40a9e3b72e3044a15',
 'transactionIndex': '0x0',
 'v': '0x26',
 'value': '0x4563918244f40000'}

and you can get the parameters doing for instance: txlist[0]['gas']

hope this helps

7
  • Thanks! i got error TypeError: getBlockNumber() missing 1 required positional argument: 'self'. Also, what attributes does txlist have that i can print out?
    – MWH
    Oct 16, 2018 at 16:12
  • You are right, I updated the code to correct the bug, I run it and it works now. Also the list have dictionaries, so to get for instance the gas of the transaction i in the list can be obtained with txlist[i]['gas']
    – Jaime
    Oct 16, 2018 at 16:37
  • Hi Jaime.. I am wondering why api do not print "gas used by transaction" such as in here etherscan.io/tx/…?
    – MWH
    Oct 18, 2018 at 11:46
  • 1
    This is because the code is reading the transactions and (if I am not wrong) the value of actually used gas is available in the receipt of the transaction. You can use the api method called myapi.getTransactionReceipt(txhash) where txhash is the hash of the transaction, then you will get the receipt that contains the the used gas value.
    – Jaime
    Oct 18, 2018 at 11:52
  • 1
    I think you should make a new question. Let me know and I will try to answer it. Writing code in the comments is not easy.
    – Jaime
    Mar 11, 2019 at 16:31

Your Answer

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

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