current position:Home>How to calculate uniswap initcode hash

How to calculate uniswap initcode hash

2022-02-03 23:16:36 Q & A of Denglian community

stay It is mentioned in this article that

There's a pit here ,createPair When you need Pair The contract ·bincode Of hash Do calculations , If you compile it yourself, you must put sol The value of the source code has changed

I don't quite understand how to change , Seek guidance

Take the answer 1:

If you use JavaScript, computing method :

var Web3 = require('web3')const artifact = require('./build/contracts/UniswapV2Pair.json')const initCodeHash = Web3.utils.keccak256(artifact.bytecode)console.log(initCodeHash)

If in Solidity Next :

   function getCodeHash() external pure returns (bytes32) {      return keccak256(type(UniswapV2Pair).creationCode);   }

Other answers 1:

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.

Random recommended