首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从BigNumber对象中提取各种元素/值

从BigNumber对象中提取各种元素/值
EN

Ethereum用户
提问于 2022-09-13 20:01:53
回答 1查看 27关注 0票数 1

当我执行const uniswapReserves = await uniswapDaiEth.getReserves();代码片段并调用console.log("uniswapReserves: ", uniswapReserves);时,它会产生以下输出:

松露(Mainnet_fork)> console.log("uniswapReserves:",uniswapReserves);

指纹:

代码语言:javascript
复制
[
  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?

非常感谢你,塞缪尔

EN

回答 1

Ethereum用户

发布于 2022-09-13 20:36:03

这看起来像响应的toString表示。

getReserves()智能契约函数返回包含3个值的元组,即reserve0reserve1blockTimestampLast。它用如下的数组表示:

代码语言:javascript
复制
[
   { _hex: '0x062f5665a81c46a329cff9', _isBigNumber: true },
   { _hex: '0xfdaa6616aaa87d55ed', _isBigNumber: true },
  1663098075,
]

在控制台中看到的另一部分只是让您知道数组中每个值的顺序:

代码语言:javascript
复制
[
 // 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
]

这只是供参考之用。

您需要按以下方式使用您的响应:

代码语言:javascript
复制
const reserve0 = uniswapReserves[0];
const reserve1 = uniswapReserves[1];
const blockTimestampLast = uniswapReserves[2];

console.log("reserve0: ", reserve0);
console.log("reserve1: ", reserve1);
console.log("blockTimestampLast: ", blockTimestampLast);
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/135559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档