英文:
Verify contract with bytes constructor argument
问题
我正在尝试通过etherscan和hardhat验证我的合同。对于没有构造函数参数的合同,一切都正常。我使用以下命令进行验证:
npx hardhat verify ${address} --network goerli
问题出现在一个具有构造函数中带有bytes
参数的合同上。我无法在命令行中传递bytes
。像"\x01\x02\x03\x04"这样的十六进制字符串也不起作用。转换为字符也不起作用。
是否有一种方法可以编写脚本来将数组化的变量作为构造函数参数传递?
英文:
I am trying to verify my contracts via etherscan and hardhat. Everything seems fine with contracts without constructor arguments. I do it with
npx hardhat verify ${address} --network goerli
The problem is with one of my contracts that has bytes
argument in the constructor. I can't pass bytes in the command line. Hex strings like "\x01\x02\x03\x04" dont work either. Converted to chars doesn't work also.
Is there a way to write script that passes the arrayified variable as constructor argument?
答案1
得分: 1
以下是翻译好的部分:
> 当构造函数具有复杂的参数列表时,您需要编写一个导出参数列表的JavaScript模块。期望的格式与构造函数列表相同。
您应该有一个名为 arguments.js
的文件,其中包含以下内容:
module.exports = [
50,
"一个字符串参数",
{
x: 10,
y: 5,
},
// 字节必须以0x前缀
"0xabcdef",
];
这些是用于合同的参数。在命令行中,使用以下命令进行验证:
npx hardhat verify --constructor-args arguments.js 部署的合同地址
英文:
Following this docs
> When the constructor has a complex argument list, you'll need to write
> a javascript module that exports the argument list. The expected
> format is the same as a constructor list
you should have a file like arguments.js
module.exports = [
50,
"a string argument",
{
x: 10,
y: 5,
},
// bytes have to be 0x-prefixed
"0xabcdef",
];
this is arguments for a contract. and in commandline:
npx hardhat verify --constructor-args arguments.js DEPLOYED_CONTRACT_ADDRESS
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论