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'
))));
有一些想法:
hexadem_ ='0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
hexadem_1 = 0xff
abiEncoded_1 = encode_abi_packed(['address', 'address'], ( token_0, token_1 ))
salt_ = web3.Web3.solidityKeccak(['bytes'], ['0x' +abiEncoded_1.hex()])
abiEncoded_2 = encode_abi_packed(['bytes', 'address', 'bytes32'], (bytes(hexadem_1), factory, salt_))
resPair = web3.Web3.solidityKeccak(['bytes','bytes'], ['0x' +abiEncoded_2.hex(), hexadem_])
能不能有人给我提个建议,哪里不对,应该怎么考虑?
首先,resPair太长,不能作为合同地址。 规则可以通过阅读以下内容来解释:https://eips.ethereum.org/EIPS/eip-1014
还请确保按字母顺序输入这两个地址。请使用.ort()函数执行此操作。以下是正确的代码:
hexadem_ ='0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
hexadem_1 = 0xff
factory = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'
abiEncoded_1 = encode_abi_packed(['address', 'address'], ('0x7825e833d495f3d1c28872415a4aee339d26ac88', '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' )) #these two addresses to be changed as fit. Currently they are TLOS and WETH
salt_ = w3.solidityKeccak(['bytes'], ['0x' +abiEncoded_1.hex()])
abiEncoded_2 = encode_abi_packed([ 'address', 'bytes32'], ( factory, salt_))
resPair = w3.solidityKeccak(['bytes','bytes'], ['0xff' + abiEncoded_2.hex(), hexadem_])[12:]
resPair
希望这对您有帮助!我发现这是一个有趣的挑战:)
这篇关于通过python计算uniswap对地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!