Verify with OpenZeppelin SDK

Verify with OpenZeppelin SDK

OpenZeppelin SDK supports verifying logic contracts with openzeppelin verify.
There is an open issue to support verifying proxy contracts: https://github.com/OpenZeppelin/openzeppelin-sdk/issues/937

The following guide walks through verifying a logic contract. (I used openzeppelin 2.5.2)

Note: Etherscan doesn’t currently support proxy contracts. EIP-1967 aims to create a standard that blockchain explorers could then implement.
Currently, if you verify the proxy contract, you will only see the ABI of the proxy (upgrade, admin, etc) and not that of the logic contract (which is the one you want to interact with). As proxies are transparent, they only answer to calls from the admin, so any calls from Etherscan to check info such as admin or implementation, will just return zero.

Token.sol

Based on SimpleToken example.

pragma solidity ^0.5.0;

import "@openzeppelin/upgrades/contracts/Initializable.sol";

// Import from OpenZeppelin contracts
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Detailed.sol";

contract Token is Initializable, ERC20, ERC20Detailed {

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

Link @openzeppelin/contracts-ethereum-package

Link the OpenZeppelin Contracts Ethereum Package into the project running openzeppelin link @openzeppelin/contracts-ethereum-package

See Linking OpenZeppelin contracts in the documentation.

$ npx openzeppelin link @openzeppelin/contracts-ethereum-package
✓ Dependency @openzeppelin/contracts-ethereum-package installed
Dependency linked to the project. Run 'openzeppelin create' to deploy one of its contracts.

Compile

Compile the contract with npx openzeppelin compile --optimizer off
Due to an Issue explicitly specify the optimizer off

Note: If you install OpenZeppelin globally, you will also need to install @openzeppelin/upgrades: npm install @openzeppelin/upgrades.

$ npx openzeppelin compile --optimizer off
✓ Compiled contracts with solc 0.5.11 (commit.c082d0b4)

Create

Create the contract on a public testnet such as Ropsten with openzeppelin create.
See Deploy to a public testnet using OpenZeppelin SDK for details on how to set this up.

$ npx openzeppelin create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate Token
? Pick a network ropsten
✓ Added contract Token
✓ Linked dependency @openzeppelin/contracts-ethereum-package 2.2.3
✓ Contract Token deployed
All contracts have been deployed
? Do you want to call a function on the instance after creating it? Yes
? Select which function initialize()
✓ Setting everything up to create contract instances
✓ Instance created at 0x7bD182A6883e25Fcb092D5837365AC989C292f9a
0x7bD182A6883e25Fcb092D5837365AC989C292f9a

Verify

Verify the logic contract with openzeppelin verify.
You need to create an Etherscan API KEY to do this.
Note: The Etherscan API doesn’t include the EVM version.

$ npx openzeppelin verify
? Pick a contract Token
? Pick a network ropsten
? Was the optimizer enabled when you compiled your contracts? No
? Select an endpoint etherscan
? Provide an etherscan API KEY ZZZZETHERSCANAPIKEYZZZZZ
✓ Contract source code of Token verified and published successfully. You can check it here: 
https://ropsten.etherscan.io/address/0x7c305F59CE83ED0F6fBA40DE90c8eaB142418558#code

Verified Logic contract: https://ropsten.etherscan.io/address/0x7c305F59CE83ED0F6fBA40DE90c8eaB142418558#code

Proxy contract: https://ropsten.etherscan.io/address/0x7bD182A6883e25Fcb092D5837365AC989C292f9a#code

1 Like