How to verify a contract deployed using Remix importing OpenZeppelin via GitHub?

Asked in a Discord channel:
How to verify a contract deployed using Remix importing OpenZeppelin via GitHub?

Example:

1 Like

I have compiled and deployed the contract on remix with the flattener plug-in enabled,

Then I have flattened the code for verification on etherscan which gives us these errors

As suggested by you to flatten the contract when you have imports (even importa from GitHub of zeplin). Then we did that but seems etherscan doesn’t know which contract bytes to compare to when you have a single file and many contracts defined in it…

So you can reproduce this if you make a simple token erc721 or erc20 and import all it’s dependencies from GitHub deploy on remix then flatten it and try to verify it…

Thanks

1 Like

Hi @x5engine,

Welcome to the community :wave:
Thanks for posting in the forum :pray:

The following is an example of verifying a contract deployed using Remix importing OpenZeppelin via GitHub.

:warning: Any solution should be appropriately tested and audited.

When OpenZeppelin CLI supports verifying regular (non-upgradeable) contracts, it will be easier to deploy, interact, test and verify from the CLI. (OpenZeppelin CLI 2.8 Release Candidate supports deploy, interact and using OpenZeppelin Test Environment - testing, but doesn’t yet verify regular contracts).


I deployed the following example contract using Remix:

Token.sol

pragma solidity ^0.5.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC20/ERC20Detailed.sol";

contract Token is ERC20, ERC20Detailed {

    constructor () public ERC20Detailed("Token", "TKN", 18) {
        _mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
    }
}

I tried using the Flattener plugin for Remix but this failed to verify on Etherscan.

Instead I created a new project locally and installed OpenZeppelin Contracts and Truffle (as truffle-flattener needs Truffle) to flatten locally.

npm i @openzeppelin/contracts
npm i truffle

Token.sol

I converted the imports to use the installed OpenZeppelin Contracts (the version needs to match what is used by the version imported by Remix.

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";

contract Token is ERC20, ERC20Detailed {

    constructor () public ERC20Detailed("Token", "TKN", 18) {
        _mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
    }
}

Flatten

I used truffle-flattener to create a flattened version of the contract

$ npx truffle-flattener ./contracts/Token.sol > ./contracts/Token_Flat.sol

Verify

I verified the contract on Etherscan as a single flat file, with compiler 0.5.16 and no optimization and it verified successfully.
Note: I didn’t have any constructor parameters in this example.

Hi @x5engine,

Were you able to verify your contract?