在 Remix 中部署 Solidity 合约时如何修复/调试错误(无效的 arrayify 值)

Gh0*_*05d 5 blockchain ethereum solidity smartcontracts remix

问题

我正在尝试通过Remix部署智能合约。不幸的是,它失败并显示一条非常无用的错误消息。

错误信息

创建 MyContract 出错:编码参数时出错:错误:无效的 arrayify 值(参数 =“值”,值 =“”,代码=INVALID_ARGUMENT,版本=字节/5.5.0)

代码

这是使用的构造函数contract

struct RRSet {
    uint32 inception;
    uint32 expiration;
    bytes20 hash;
}

constructor(bytes memory _anchors) {
    // Insert the 'trust anchors' - the key hashes that start the chain
    // of trust for all other records.
    anchors = _anchors;
    rrsets[keccak256(hex"00")][DNSTYPE_DS] = RRSet({
        inception: uint32(0),
        expiration: uint32(3767581600), // May 22 2089 - the latest date we can encode as of writing this
        hash: bytes20(keccak256(anchors))
    });
    emit RRSetUpdated(hex"00", anchors);
}
Run Code Online (Sandbox Code Playgroud)

一些想法

我的合约用来is继承抽象合约和常规合约。有没有办法查看错误或源自何处,或者是否有可能对其进行调试?

Pet*_*jda 8

构造函数采用字节数组作为参数。

当您传递空值时,会导致问题中提到的错误消息。这是因为您实际上传递的是“无值”,而不是“空字节数组”。

空值

创建 MyContract 出错:编码参数时出错:错误:无效的 arrayify 值(参数 =“值”,值 =“”,代码=INVALID_ARGUMENT,版本=字节/5.5.0)

如果要传递空字节数组,则需要使用[]or0x表达式(两个选项都有效):

空数组

空数组