I'm trying to compute the address of a Uniswap pair offline with web3js as per this Solidity example:
address factory = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
address token0 = 0xCAFE000000000000000000000000000000000000; // change me!
address token1 = 0xF00D000000000000000000000000000000000000; // change me!
address pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
))));
I have the following function in js to compute the pair address:
function getPair(token0, token1) {
const hexadem = '0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f';
const factory = '0xBCfCcbde45cE874adCB698cC183deBcF17952812';
let salt = web3.utils.soliditySha3(token0, token1);
let pair = web3.utils.soliditySha3('0xff', factory, salt, hexadem);
console.log(pair);
return pair
}
Is this the correct implementation of the above Solidity example? When I run the code with two token addresses I get a string which is too long to be a pair address. Any ideas?