I am trying (in solidity) to write a contract that needs some statistics on the past few miners. E.g., who mined the last 100 blocks. I know that for the current block I get the address as explained here. I can also get the last 256 blockhashes, but is it at all possible to get the address of the miners of the last blocks?

  • Do you have a requirement to achieve this only through a contract? You can also get this information through a JS snippet in the console. – galahad Jun 27 '16 at 14:55
  • Yes, I would want it to be computed as part of the contract code. Otherwise, how would the contract act on the information? – Guut Boy Jun 27 '16 at 14:59
  • Through events. Also, check this. – galahad Jun 27 '16 at 15:10
  • I do not see how events help here? Of course, I could get the information outside of the contract, but in order for the contract to act on the information, wouldn't I have to call the contract with this as data? And how can people using the contract then know that I was using the correct information? What you suggest seem to be a security problem. But maybe I am not understanding correctly? – Guut Boy Jun 27 '16 at 15:19
  • Yes. You would have to call the contract with this data. Achieving this through a smart contract is ideal, since it doesn't have any security concerns. If you really want to use events and provide assurance to people that the information provided is correct, you can sign this information with a private key but this just seems like a Rube Goldbergian alternative to using a smart contract which is reliable (since it's on the blockchain). I can't comment on which method to use because I'm not aware of what you're trying to achieve. – galahad Jun 27 '16 at 16:33

No, it's not possible directly within Solidity and the EVM.

As you've noted, these are the only block variables available:

block.blockhash(uint blockNumber) returns (bytes32): hash of the given block - only works for 256 most recent blocks
block.coinbase (address): current block miner’s address
block.difficulty (uint): current block difficulty
block.gaslimit (uint): current block gaslimit
block.number (uint): current block number
block.timestamp (uint): current block timestamp
  • Thank you, that is what I thought. So I guess if one really wants this information in a contract you have to rely on an oracle. – Guut Boy Jun 28 '16 at 12:46
  • Yes, but it can be an oracle that cannot cheat (trustless). A simple way (there may be optimizations) is for the oracle to pass your contract the block header and the block number for it. Your contract can check that its hash matches block.blockhash and then extract the miner's address from the header (see the Ethereum Yellow Paper, which names the miner address as "beneficiary"). – eth Jun 28 '16 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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