迁移合同与松露给了我交易恢复

Migrating contract with truffle gives me transaction revert

我的合同 .sol 文件如下所示:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/token/ERC777/ERC777.sol";

contract ERC777MainToken is ERC777{
  constructor(address[] memory defaultOperators) ERC777("COIN", "COIN", defaultOperators) { }
}

迁移看起来像这样:

const ERC777MainToken = artifacts.require("ERC777MainToken");

module.exports = async function(_deployer) {
  const mainToken = await _deployer.deploy(ERC777MainToken, ["0x5d95F05Dd72A5cB9ea2ee2DC271B03A41C933Cad"])
};

truffle migrate 我收到以下错误:

"ERC777MainToken" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:74:1)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:61:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:212:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.runAll (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:263:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:228:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)

有什么想法吗?我检查了每个构造函数,没有人有任何要求条件。

我找到问题了。来自 open zeppelin 的 ERC777 合约有一个硬编码的 memeber _ERC1820_REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24) 这是主网的 global ERC1820 Registry 但由于我在本地网上,这个地址最多没有。

contract ERC777 is Context, IERC777, IERC20 {
    using Address for address;

    IERC1820Registry constant internal _ERC1820_REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);

    mapping(address => uint256) private _balances;

   ....
}

并且构造函数正在尝试访问此地址上的合约:

 constructor(
        string memory name_,
        string memory symbol_,
        address[] memory defaultOperators_
    ) {
        _name = name_;
        _symbol = symbol_;

        _defaultOperatorsArray = defaultOperators_;
        for (uint256 i = 0; i < defaultOperators_.length; i++) {
            _defaultOperators[defaultOperators_[i]] = true;
        }

        // register interfaces
        _ERC1820_REGISTRY.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
        _ERC1820_REGISTRY.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
    }

但是由于本地网络上的这个地址可能是空的,而且 100% 不是应该的,因此交易被还原。

如果您的代码中有 requirerevert 语句,请添加如下错误消息:require(condition, errorMessage);revert (errorMessage);