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!

2

1 Answer 1

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']}

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.