How to verify an ERC721 inheriting from OpenZeppelin?

I am trying to Verify & Publish ERC-721 Contract Source Code. But Open Zeppelin Import Causing error.

This might be because I’m not adding contract library address. So what to add for Open Zeppelin?



Hi @hardsuccess

Assuming you are using openzeppelin-solidity there is no linked library for the OpenZeppelin contracts, e.g. SafeMath only has internal library functions.
Libraries can be seen as implicit base contracts of the contracts that use them. They will not be explicitly visible in the inheritance hierarchy, but calls to library functions look just like calls to functions of explicit base contracts ( L.f() if L is the name of the library). Furthermore, internal functions of libraries are visible in all contracts, just as if the library were a base contract. Of course, calls to internal functions use the internal calling convention, which means that all internal types can be passed and types stored in memory will be passed by reference and not copied. To realize this in the EVM, code of internal library functions and all functions called from therein will at compile time be pulled into the calling contract, and a regular JUMP call will be used instead of a DELEGATECALL .

The easiest way to verify a contract inheriting from OpenZeppelin on Etherscan is as a single flat file.
First flatten the contract using nomiclabs/truffle-flattener.

Then verify the flattened contract on Etherscan.
When verifying you need to ensure that you select Compiler Type as Solidity Single File and the appropriate Compiler Version.

As an example I verified the following sample contract:

GameItem.sol (ERC721 contract)

GameItem example contract from OpenZeppelin documentation

pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol";
import "openzeppelin-solidity/contracts/drafts/Counters.sol";

contract GameItem is ERC721Full {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721Full("GameItem", "ITM") public {

    function awardItem(address player, string memory tokenURI) public returns (uint256) {

        uint256 newItemId = _tokenIds.current();
        _mint(player, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;

Compile the contract, making note of the compiler version (in this case 0.5.8+commit.23d335f2)

$ npx truffle compile

Compiling your contracts...
> Compiling ./contracts/GameItem.sol
> Compiling ./contracts/Migrations.sol
> Compiling openzeppelin-solidity/contracts/drafts/Counters.sol
> Compiling openzeppelin-solidity/contracts/introspection/ERC165.sol
> Compiling openzeppelin-solidity/contracts/introspection/IERC165.sol
> Compiling openzeppelin-solidity/contracts/math/SafeMath.sol
> Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721.sol
> Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721Enumerable.sol
> Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol
> Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721Metadata.sol
> Compiling openzeppelin-solidity/contracts/token/ERC721/IERC721.sol
> Compiling openzeppelin-solidity/contracts/token/ERC721/IERC721Enumerable.sol
> Compiling openzeppelin-solidity/contracts/token/ERC721/IERC721Metadata.sol
> Compiling openzeppelin-solidity/contracts/token/ERC721/IERC721Receiver.sol
> Compiling openzeppelin-solidity/contracts/utils/Address.sol
> Artifacts written to /.../build/contracts
> Compiled successfully using:
   - solc: 0.5.8+commit.23d335f2.Emscripten.clang

Create a flattened version of the contract using nomiclabs/truffle-flattener

npx truffle-flattener ./contracts/GameItem.sol > ./contracts/FlatGameItem.sol

Start the verification process on etherscan

Specify the contract address from when you deployed to the network.
Set the Compiler Type as Solidity (Single file)
Set the Compiler Version used when you compiled the contract

Then paste in the flattened version of the smart contract, click I’m not a robot and press Publish and Verify

Your contract should then be verified on etherscan.
Example of the contract I verified:


Thanks. That worked :slight_smile:

1 Like

Awesome @hardsuccess glad you can verify your contract.