0

Is it possible to read the block chain from within a contract? Specifically, I want to know if I can see how much ether user A has spent during the last 50 or so blocks.

I didn't find anything in the documentation that could read something from previous mined blocks, so I suppose I'd need something like Oraclize to do this.

  • 2
    No, you can't do this without some sort of help from outside the contract. (It might be possible to do this in a trustless fashion by submitting some sort of proof that can be checked against block hashes, which are known to smart contracts for the most recent 255 blocks.) – user19510 Feb 14 '18 at 22:56
1

Directly you can't access block data for x transaction in solidity, but below block info you can access in solidity.

block.blockhash(uint blockNumber) returns (bytes32): hash of the given block number - Its only works for 256 most recent blocks
block.coinbase (address): current block miner 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

Save above variables in solidity then use oraclize service or generate an event use clients to listen an events. From there you can read block inputs and push back to your contract.

More details refer below link

http://solidity.readthedocs.io/en/latest/units-and-global-variables.html

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.