Solidity – Why Does the blockhash(block.number) Function Return 0x000… Address?

solidity

i learning solidity. i test blockhash(block.number) function in local and test net .
the code is

// SPDX-License-Identifier: SimPL-3.0
pragma solidity ^0.8.0;

contract BlockTest2{

     function test2() public view returns(bytes32 b46,uint number45){//当前blockhash 返回是0 原因未知
         number45 = block.number; // 当前区块号
         b46=blockhash(number45);   
    }
}

the result is

enter image description here

Best Answer

The blockhash of the current block is always 0 (ethereum yellow paper page 33).

If you want a meaningful result, try number45 = block.number-1.

Related Topic