Ethers.js Abicoder返回未定义的

发布于 2025-01-20 10:17:47 字数 381 浏览 1 评论 0原文

我正在尝试使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一萌ing 2025-01-27 10:17:47

这对我有用;

我删除了 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 my package.json file, changed the ethers version to ethers@"5.7.2" from ethers@"^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 after npm i.

I guess the new "ethers" version is a bit unstable for now, so I just downgrade.

家住魔仙堡 2025-01-27 10:17:47

您可以使用Ethers V6文档

现在移动此功能,并且可以轻松访问

const AbiCoder = new ethers.AbiCoder()

You can use ethers v6 documentation

Now this functionality was moved and can be easily accessed

const AbiCoder = new ethers.AbiCoder()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文