EIP-1052 Introduces the EXTCODEHASH EVM opcode which takes an address as a parameter and returns the hash of the bytecode located at that address.
Solidity contract with asm call to extcodehash
contract ContractHash {
function getContractHash(address a) public view returns (bytes32 hash) {
assembly {
hash := extcodehash(a)
}
}
}
docker run -v $(pwd)/contracts:/tmp/contracts ethereum/solc:stable --bin --abi --evm-version constantinople /tmp/contracts/ContractHash.sol
======= /tmp/contracts/ContractHash.sol:ContractHash =======
Binary:
608060405234801561001057600080fd5b5060b98061001f6000396000f3fe608060405260043610601c5760003560e01c8063f5441a74146021575b600080fd5b348015602c57600080fd5b50606c60048036036020811015604157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506082565b6040518082815260200191505060405180910390f35b6000813f905091905056fea165627a7a72305820416e7621097e451b973693d88c35992144d2e2aaa974751c620fdfbe0c4e14990029
Contract JSON ABI
[{"constant":true,"inputs":[{"name":"a","type":"address"}],"name":"getContractHash","outputs":[{"name":"hash","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"}]
There is an instance on Ropsten at 0x1B6841A7B559eB1c35F5Bb78e7da119fe8D11121
let addressOfContract = _INSERT_CONTRACT_ADDRESS_HERE_
let Web3 = require('web3')
let web3 = new Web3('https://ropsten.infura.io')
let contractBytecode = web3.eth.getCode(addressOfContract)
web3.utils.keccak256(contractBytecode)
{
"linkReferences": {},
"object": "THINGS YOU NEEDED HERE", copy only this part from remix to generate your hash
"opcodes": "-",
"sourceMap": "-"
}
keccak256 hash
Go to https://emn178.github.io/online-tools/keccak_256.html, paste in the content, and make sure you select Input Type as Hex, then you will get the init code hash.