Solidity

部署時重新混合 VM 錯誤

  • August 9, 2021

我正在嘗試部署此程式碼。

// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC777/ERC777.sol";

contract GLDToken is ERC777 {
   constructor(uint256 initialSupply, address[] memory defaultOperators)
       ERC777("test", "TEST", defaultOperators)
   {
       _mint(msg.sender, initialSupply, "", "");
   }
}

它編譯成功,但是當我點擊事務時拋出錯誤。

creation of GLDToken errored: VM error: revert.

revert
   The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
Debug the transaction to get more information.

我不知道如何修復它,這些是我正在使用的參數。

經過一番摸索,我相信我找到了問題所在。問題在於註冊合約介面。這是建構接收鉤子所必需的。

如果您查看參考 OpenZeppelin 原始碼<https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC777/ERC777.sol#L31>,您會看到它使用硬編碼地址 (0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24)作為系統資料庫。該地址(至少)存在於主網上,但顯然不存在於您的 JavaScript VM 中。

<https://docs.openzeppelin.com/contracts/4.x/erc777>上的 OpenZeppelin ERC777 文件忘記提及該範例僅適用於主網。

如果您想讓它在您自己的環境中執行,您首先必須部署系統資料庫並更改硬編碼地址。由於 OpenZeppelin 合同不打算在本地更改(您應該只擴展它們)並且變數是internal(不能被覆蓋)我真的不知道他們希望人們如何使用模板。我猜你只需要在本地修改原始碼。

引用自:https://ethereum.stackexchange.com/questions/106814