2

Within a program, I would like to process a list of all normal transactions for an Ethereum block. Specifically for each transaction in the block the transferred ETH value, sender address and receiver address is needed.

Explorers have such lists (e.g. https://etherscan.io/txs?block=12702435), but I cannot find an API which provide this information directly in one API call.

In two steps it is doable:

  1. get all txhashes eg. https://api.blockcypher.com/v1/eth/main/blocks/12702435
  2. get sender, receiver and amount for each txhash However, this solution is also difficult because of API rate limits

Thank a lot for your help!

Freude
  • 131
  • 6
  • https://ethereum.stackexchange.com/questions/2531/common-useful-javascript-snippets-for-geth/2541 – user216 Jun 25 '21 at 10:13
  • 1
    Try one of this scripts: https://ethereum.stackexchange.com/questions/2531/common-useful-javascript-snippets-for-geth/2541 – user216 Jun 25 '21 at 10:15

1 Answers1

1

@user216: Thanks for your comment. Indeed, an easy way is to install geth and run a light node with

geth --syncmode "light"

Then install web3 via pip. Afterwards the following Python code works :)

w3 = web3.Web3(web3.Web3.IPCProvider('/home/user/.ethereum/geth.ipc'))
block = w3.eth.get_block(12704257) # example for a recent block
for tx_hash in block['transactions']:
    tx = w3.eth.get_transaction(tx_hash)
    tx_obj = {'addr_sender': tx['from'], 'addr_receiver': tx['to'], 'value': tx['value']}
Freude
  • 131
  • 6