I want to write a script to analyze mining rewards.
What is the best way to query for the amount of mining rewards of a certain block?
It seems possible to query the address of the lucky miner:
web3.eth.getBlock(200).miner
"0xbb7b8287f3f0a933474a79eae42cbca977791171"
Then I can somehow delve into the account and pick the transaction at certain block. Is this the best way? Or do you know shortcuts? And how to do it?
Best Answer
Mining rewards aren't transactions, so you can't query them in the usual way. As per this previous answer:
You'll either need to calculate the reward yourself, or use somebody else's API.
Calculating the reward yourself
The algorithm for calculating the reward - as stated on the Mining wiki page - is as follows:
The data required for the second and third parts can be queried from the block using:
web3.eth.getBlock(<block>).gasUsed
web3.eth.getBlock(<block>).uncles
(Note: The reward per uncle is /32 of the static reward, i.e. 5 / 32.)Using someone else's API
Etherscan is one of the block explorers that includes details of the reward for a given block (see here for an example). Details of their APIs can be found either on their site, or, for Python bindings, on this GitHub page. (I haven't checked that these return the reward details, so YMMV.)
EDIT : The static reward is now 3.0 Ether