Can you tell me what this piece of solidity code means please?

uint number = uint(block.blockhash(block.number - 1)) % 37;

Thank you

Take care


1 Answer 1


Well, block.number returns the current block number and the builtin function block.blockhash, or rather only blockhash expects a block number and returns the corresponding hash of this block.

So, this line of code takes the block hash of the previous block (block.number -1), converts this hash to a uint, and then performs a modulus 37 operation on it.


If the current block number/height would be 10634585, we take the hash the previous block (with block height 10634584) which is


.. converted to a uint and calculating modulo 37 gives us

72022899595671774698588476995950590173605856445212735706703646854236147888411 % 37 = 7

Hope this helps


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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