Unable to verify contract importing OpenZeppelin Contracts docs branch via GitHub on Etherscan

Hello, I can’t verify my contract on etherscan, could you help me ?

Here is the error message I get:
Error! Unable to generate Contract ByteCode and ABI (General Exception, unable to get compiled [bytecode])

Here is my code:

pragma solidity ^0.5.0;

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

/**
 * @title TRUST
 
 */
contract TRT is ERC20, ERC20Detailed {

    uint256 private _minimumSupply = 1000 * (10 ** 18);

    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    constructor () public ERC20Detailed("TRUST", "TRT", 18) {
        _mint(msg.sender, 17000 * (10 ** uint256(decimals())));
    }

    function transfer(address to, uint256 amount) public returns (bool) {
        return super.transfer(to, _partialBurn(amount));
    }

    function transferFrom(address from, address to, uint256 amount) public returns (bool) {
        return super.transferFrom(from, to, _partialBurn(amount));
    }

    function _partialBurn(uint256 amount) internal returns (uint256) {
        uint256 burnAmount = _calculateBurnAmount(amount);

        if (burnAmount > 0) {
            _burn(msg.sender, burnAmount);
        }

        return amount.sub(burnAmount);
    }

    function _calculateBurnAmount(uint256 amount) internal view returns (uint256) {
        uint256 burnAmount = 0;

        // burn amount calculations
        if (totalSupply() > _minimumSupply) {
            burnAmount = amount.mul(25).div(1000);
            uint256 availableBurn = totalSupply().sub(_minimumSupply);
            if (burnAmount > availableBurn) {
                burnAmount = availableBurn;
            }
        }

        return burnAmount;
    }
}

Here is the address of the contract:
0xadd42c3a88a347b7a7df7bb57a2a76ecb6ef39cd

Kind Regards.

1 Like

Hello @genesis24,

In order to verify contract on etherscan, you have to make sure you know the exact version of the compiler used. Also, you have to verify which options you used (optimisations, …).

Some IDE, including remix tat you seem to be using, include modules that does the verification for you. You should have a look at their documentation.

1 Like

Hi @genesis24,

In your contract you are importing OpenZeppelin Contracts from a documentation branch. You should only import via GitHub an official release. This will potentially cause you issues.

From your bytecode you used Solidity 0.5.17. You will need to specify whether you compiled with optimization.

You can try converting your GitHub imports to npm imports and verify via Hardhat, assuming that this code is the same as in OpenZeppelin Contracts 2.5.1.

I use the following process to verify: Verify smart contract inheriting from OpenZeppelin Contracts

Hi @genesis24,

I used the following process Verify smart contract inheriting from OpenZeppelin Contracts

I converted your GitHub imports to npm imports

pragma solidity ^0.5.0;

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

/**
 * @title TRUST
 
 */
contract TRT is ERC20, ERC20Detailed {

    uint256 private _minimumSupply = 1000 * (10 ** 18);

    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    constructor () public ERC20Detailed("TRUST", "TRT", 18) {
        _mint(msg.sender, 17000 * (10 ** uint256(decimals())));
    }

    function transfer(address to, uint256 amount) public returns (bool) {
        return super.transfer(to, _partialBurn(amount));
    }

    function transferFrom(address from, address to, uint256 amount) public returns (bool) {
        return super.transferFrom(from, to, _partialBurn(amount));
    }

    function _partialBurn(uint256 amount) internal returns (uint256) {
        uint256 burnAmount = _calculateBurnAmount(amount);

        if (burnAmount > 0) {
            _burn(msg.sender, burnAmount);
        }

        return amount.sub(burnAmount);
    }

    function _calculateBurnAmount(uint256 amount) internal view returns (uint256) {
        uint256 burnAmount = 0;

        // burn amount calculations
        if (totalSupply() > _minimumSupply) {
            burnAmount = amount.mul(25).div(1000);
            uint256 availableBurn = totalSupply().sub(_minimumSupply);
            if (burnAmount > availableBurn) {
                burnAmount = availableBurn;
            }
        }

        return burnAmount;
    }
}

Then I verified using Hardhat

$ npx hardhat verify --network mainnet 0xadd42c3a88a347b7a7df7bb57a2a76ecb6ef39cd
Compiling 6 files with 0.5.17
Compilation finished successfully
Compiling 1 file with 0.5.17
Successfully submitted source code for contract
contracts/TRT.sol:TRT at 0xadd42c3a88a347b7a7df7bb57a2a76ecb6ef39cd
for verification on Etherscan. Waiting for verification result...

Successfully verified contract TRT on Etherscan.
https://etherscan.io/address/0xadd42c3a88a347b7a7df7bb57a2a76ecb6ef39cd#code

You can see your verified code on Etherscan: