当我执行const uniswapReserves = await uniswapDaiEth.getReserves();代码片段并调用console.log("uniswapReserves: ", uniswapReserves);时,它会产生以下输出:
松露(Mainnet_fork)> console.log("uniswapReserves:",uniswapReserves);
指纹:
[
BigNumber { _hex: '0x062f5665a81c46a329cff9', _isBigNumber: true },
BigNumber { _hex: '0xfdaa6616aaa87d55ed', _isBigNumber: true },
1663098075,
reserve0: BigNumber { _hex: '0x062f5665a81c46a329cff9', _isBigNumber: true },
reserve1: BigNumber { _hex: '0xfdaa6616aaa87d55ed', _isBigNumber: true },
blockTimestampLast: 1663098075
]它清楚地返回两个传递的令牌地址中每个地址的输出保留值。问题是如何提取或引用BigNumber值,例如reserve0?
非常感谢你,塞缪尔
发布于 2022-09-13 20:36:03
这看起来像响应的toString表示。
getReserves()智能契约函数返回包含3个值的元组,即reserve0、reserve1和blockTimestampLast。它用如下的数组表示:
[
{ _hex: '0x062f5665a81c46a329cff9', _isBigNumber: true },
{ _hex: '0xfdaa6616aaa87d55ed', _isBigNumber: true },
1663098075,
]在控制台中看到的另一部分只是让您知道数组中每个值的顺序:
[
// This is the `reserve0` value, the first value in the array
BigNumber { _hex: '0x062f5665a81c46a329cff9', _isBigNumber: true },
// This is the `reserve1` value, the second value in the array
BigNumber { _hex: '0xfdaa6616aaa87d55ed', _isBigNumber: true },
// This is the `blockTimestampLast` value, the third value in the response array
1663098075,
// These values are in order, they indicate that the `reserve0` will be in the first position of the array (index 0). `reserve1` in the second place (index 1), and `blockTimestampLast` in the third place (index 2).
reserve0: BigNumber { _hex: '0x062f5665a81c46a329cff9', _isBigNumber: true },
reserve1: BigNumber { _hex: '0xfdaa6616aaa87d55ed', _isBigNumber: true },
blockTimestampLast: 1663098075
]这只是供参考之用。
您需要按以下方式使用您的响应:
const reserve0 = uniswapReserves[0];
const reserve1 = uniswapReserves[1];
const blockTimestampLast = uniswapReserves[2];
console.log("reserve0: ", reserve0);
console.log("reserve1: ", reserve1);
console.log("blockTimestampLast: ", blockTimestampLast);https://ethereum.stackexchange.com/questions/135559
复制相似问题