Search code examples
ethereumsoliditysmartcontractscryptocurrencyetherscan

Verify and Publish Contract on Etherscan with Imported OpenZeppelin file


I'm currently building a ERC721 compliant contract and have published the contract here: https://ropsten.etherscan.io/address/0xa513bc0a0d3af384fefcd8bbc1cc0c9763307c39 - I'm now attempting to verify and publish the contract source code

The start of my file looks like so:

// 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 {

However, when attempting to verify and publish with a Solidity single file I have the following error appear:

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"
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Can anyone point me in the direction to either 1. Solve this problem or 2. Documentation on how to appropriately write a contract that has dependencies imported that can be verified with Etherscan. Right now this is just a single file contract.


Solution

  • Simply put I had to go down a rabbit hole to work this out as I'm pretty new to Solidity.

    I had to do the following;

    1. Learn and use https://www.trufflesuite.com/ to setup a project and put my contract there (Using Ganache helped a lot with testing for anyone new to Solidity too)
    2. Use HD Wallet provider package and follow tutorial here to get it on ropsten Etherscan https://medium.com/coinmonks/5-minute-guide-to-deploying-smart-contracts-with-truffle-and-ropsten-b3e30d5ee1e
    3. Finally, use truffle-plugin-verify https://github.com/rkalis/truffle-plugin-verify to verify the contract on Etherscan

    All in all, I am pretty sure there is no way within the Etherscan web app to verify a contract that contains an imported file.

    The final product is here if anyone is interested in seeing how I structured it all https://github.com/lukecurtis93/viper-nft (it's just a CryptoKitties clone I found online as a base and updated it all)