Ethers.js Abicoder返回未定义的
我正在尝试使用nodejs应用中使用Abicoder函数编码CallData的功能参数。但是返回的值不确定。
这是我的代码段:
const abiCoder = new ethers.utils.AbiCoder();
const data = abiCoder.encode(["address"], ["0x72c4b017a057505e621c4481ff6ee1aa628373a3"])
console.log(data);
//console output
undefined
我还尝试使用编码eparameter函数在Web3.js中运行相同的功能,但它仍然返回相同的“未定义”。我是否缺少预设的设置?
I am trying to encode function parameters for calldata using AbiCoder function in my nodejs app. But the returned value is undefined.
Here's my code snippet:
const abiCoder = new ethers.utils.AbiCoder();
const data = abiCoder.encode(["address"], ["0x72c4b017a057505e621c4481ff6ee1aa628373a3"])
console.log(data);
//console output
undefined
I also tried to run the same function in web3.js using encodeParameter function but it still returns the same 'undefined'. Is there a pre setup that I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用;
我删除了
package.json
文件中的节点模块文件夹rm -rf node_modules
,将 ethers 版本更改为ethers@"5.7.2"
> 从ethers@"^6.1.0
,并将我的"@nomicfoundation/hardhat-toolbox"
(如果正在使用)更改为版本“^2.0.2”
与npm i之后的ethers版本保持一致,我猜新的“ethers”版本现在有点不稳定,所以我。只是降级。
This is what worked for me;
I removed the node modules folder
rm -rf node_modules
, in mypackage.json
file, changed the ethers version toethers@"5.7.2"
fromethers@"^6.1.0
, and also changed my"@nomicfoundation/hardhat-toolbox"
(if in use) to version"^2.0.2"
to be in line with the ethers version then afternpm i
.I guess the new "ethers" version is a bit unstable for now, so I just downgrade.
您可以使用Ethers V6文档
现在移动此功能,并且可以轻松访问
You can use ethers v6 documentation
Now this functionality was moved and can be easily accessed