In solidity we retrieve owner address by using msg.sender, 1.But how to retrieve the block address on which the contract was deployed ?

  • Loop through the blocks and look for a contract deployment transaction at the address of the constract. This cannot be done inside a smart contract. Commented Jan 18, 2022 at 13:53

1 Answer 1


As far as I know there isn't a "block address", you can retrieve the block number (the closest thing to an address) with block.number. This is the block number of the block where the transaction executing your code is included. You can get the block hash with blockhash(block_number) but this cannot work with blockhash(block.number) so it's only usable for old blocks (but not too old, maximum 256).

You could add in your constructor a line that stores block.number in a public variable of your smart contract.

Generally speaking, internally (i.e. using Solidity or even more generally the EVM), you can see (only a part of) the current status of the blockchain. Despite the fact that the entire blockchain is public by nature, it is only if you analyze it externally, not using a smart contract. So you have to explicitly code these mechanisms.

  • And to add onto this, if you wanted to know the block the contract was deployed in, you should record that block number in the contract constructor/initialize method using a storage or immutable variable.
    – Bruce
    Commented Dec 27, 2022 at 6:28

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.