使用导入的 OpenZeppelin 文件在 Etherscan 上验证并发布合约

Luk*_*tis 9 ethereum solidity smartcontracts cryptocurrency etherscan

我目前正在构建符合 ERC721 标准的合约,并已在此处发布合约: https: //ropsten.etherscan.io/address/0xa513bc0a0d3af384fefcd8bbc1cc0c9763307c39 - 我现在正在尝试验证并发布合约源代码

我的文件的开头如下所示:

// SPDX-License-Identifier: MIT

// We will be using Solidity version 0.8.4
pragma solidity 0.8.4;

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

contract ViperToken is ERC721 {
Run Code Online (Sandbox Code Playgroud)

但是,当尝试使用 Solidity 单个文件进行验证和发布时,出现以下错误:

ParserError: Source "@openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File import callback not supported
 --> myc:6:1:
  |
6 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)

任何人都可以向我指出 1. 解决此问题或 2. 有关如何正确编写导入了可以使用 Etherscan 验证的依赖项的合约的文档。现在这只是一个单文件合同。

Luk*_*tis 13

简而言之,我必须深入研究才能解决这个问题,因为我对 Solidity 还很陌生。

我必须做以下事情;

  1. 学习并使用https://www.trufflesuite.com/来设置一个项目并将我的合同放在那里(使用 Ganache 对任何刚接触 Solidity 的人进行测试也有很大帮助)
  2. 使用 HD 钱包提供商包并按照此处的教程在 ropsten Etherscan 上获取它https://medium.com/coinmonks/5-minute-guide-to-deploying-smart-contracts-with-truffle-and-ropsten-b3e30d5ee1e
  3. 最后,使用 truffle-plugin-verify https://github.com/rkalis/truffle-plugin-verify在 Etherscan 上验证合约

总而言之,我非常确定 Etherscan Web 应用程序无法验证包含导入文件的合约。

如果有人有兴趣了解我如何构建它,最终产品就在这里https://github.com/lukecurtis93/viper-nft(这只是我在网上找到的 CryptoKitties 克隆作为基础并更新了所有内容)


小智 6

如果您正在编译到 REMIX IDE

  1. 来自 REMIX IDE

  2. 搜索“Flattener”插件

  3. 右键单击文件 -> 展平 yourcontract.sol

  4. 在 Etherscan 上复制/粘贴