【问题标题】:Using ethers.utils.FormatTypes.full returns object not string使用 ethers.utils.FormatTypes.full 返回对象而不是字符串
【发布时间】:2022-01-09 16:57:54
【问题描述】:

我想使用 truffle 创建的 json 文件从人类可读的 ABI 创建一个表单。所以想法是获取字符串 Human-Readable ABI,然后使用正则表达式剪切并使用不同的部分来创建我的表单。但是使用ethers.utils.FormatTypes.full 不会像文档建议的那样返回字符串。

这是我的代码:

 const iface = await new ethers.utils.Interface(Bank.abi);
 iface.format(ethers.utils.FormatTypes.full);

预期输出:

[
 'function deposit() public payable',
 'function withdraw(uint256 _amount)',
 'function checkAssets() public view returns(uint256)'
];

实际输出: 根据文档:Converting Between Formats

ethers.utils.FormatTypes.full ⇒ 字符串。 这是一个完整的人类可读字符串,包括所有参数名称、任何可选修饰符(例如 indexed、public 等)和有助于人类可读性的空格。

但相反,它返回一个对象。 有人可以帮忙吗?

【问题讨论】:

    标签: javascript reactjs ethereum human-readable ethers.js


    【解决方案1】:

    查看the codeformat 在所有情况下肯定会返回一个字符串。

    从您的代码摘录中,不清楚您在控制台中记录了什么。

    应该是这样的:

     const iface = await new ethers.utils.Interface(Bank.abi);
     console.log('Formatted ABI', iface.format(ethers.utils.FormatTypes.full));
    

    从您在屏幕截图中发布的内容来看,您似乎正在记录 iface 对象本身。

    如果您提供您正在使用的完整代码,我很乐意编辑此答案。

    【讨论】:

    • 你是个传奇人物,我在记录 iface。太感谢了。我不知道为什么我没有看到这个。
    • 很高兴我能帮上忙! :)
    猜你喜欢
    • 2017-07-18
    • 2011-07-29
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多