通过javascript计算uniswap对地址

时间:2021-07-22 18:45:39

标签: solidity web3js

我正在尝试按照 this Solidity 示例使用 web3js 离线计算 Uniswap 对的地址:

    clocksToDisplay = clocksToDisplay
        .sort((a: any, b: any) => {
          return a.station - b.station || a.totalDays - b.totalDays;
        })
        .map((clock: any) => {
          const details = {
            title: clock.clockName,
            info: {
              headers: ['Station', 'Status', 'Event Description'],
              labels: ['station', 'status', 'description'],
              data: [
                {
                  station: clock.station,
                  status: <img src={StatusIcon} alt="Status Icon" />,
                  description: clock.eventDescription
                }
              ]
            },
            history: {
              headers: [
                'Date Of Reset',
                'IR#',
                'Event Description',
                'Tool To Prevent Event'
              ],
              labels: ['date', 'irNum', 'description', 'toolToPrevent'],
              data: []
            }
          };

我在js中有以下函数来计算对地址:

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'
))));

这是上述 Solidity 示例的正确实现吗?当我使用两个令牌地址运行代码时,我得到一个太长的字符串,无法成为一对地址。有什么想法吗?

0 个答案:

没有答案