【问题标题】:Truffle returning Big Number松露返回大数字
【发布时间】:2022-01-13 15:05:34
【问题描述】:

我正在编写教程,但一直遇到此错误。 我尝试在松露中运行 toString(),并尝试将 uint 转换为可靠的字符串。如果有人能指出我的错误,将不胜感激。

   function balanceOf(address _owner) public view returns (uint256 toString){
    require(_owner != address(0),'owner query for non-existent token');
    return _OwnedTokensCount[_owner];

truffle(development)> truffle compile
truffle(development)> truffle migrate
truffle(development)> kryptoBird = await KryptoBirdz.deployed()

// I mint a few tokens 
truffle(development)> kryproBird.mint('https...1')

truffle(development)> kryptoBird.ownerOf(0)
'0x5582aFA98dDD9BB16f33d198911C48fB3B20de60'

truffle(development)> 
kryptoBird.balanceOf('0x5582aFA98dDD9BB16f33d198911C48fB3B20de60')

BN {negative: 0, words: [ 1 <1 empty item>], length:1 , red: null  }

这应该返回一个整数

【问题讨论】:

  • 欢迎来到 StackOverflow。请编辑问题并将代码和控制台输出作为文本发布(您可以使用 Markdown 或编辑器中的{} 符号来格式化代码),而不是图像。它允许回答者复制粘贴部分内容并更好地解决问题。您可以在tour 页面中找到更多如何提出好问题的提示。

标签: solidity tostring truffle


【解决方案1】:

作为解决方案,您可以应用它

balanceOfAcc = await kryptoBird.balanceOf('0x5582aFA98dDD9BB16f33d198911C48fB3B20de60') balanceOfAcc.toString()

【讨论】:

  • 非常感谢,运行它解决了我的问题。我跑了'balanceOf = await kryptoBird.balanceOf('0x5582aFA98dDD9BB16f33d198911C48fB3B20de60') balanceOf.toString()'
猜你喜欢
  • 2020-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-15
  • 2022-08-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多