OpenZeppelin Contract Verification

Instructions for various development environments

Page partially based on OpenZeppelin Tutorial.

Due to compiler constraints, contracts which include OpenZeppelin-related source contracts (e.g., import@openzeppelin/contracts/access/Ownable.sol;) can cause problems with verification. The sources must be provided explicitly during the contract verification process.

Below we describe verification information when including these contracts specific to different development environments.

Hardhat

Hardhat is a full-featured development environment for contract compilation, deployment, and verification. The Hardhat Verification plugin supports contract verification on Quaiscan and includes in-built functionality to address verification with OpenZeppelin-based imports.

A separate tutorial about contract verification via Hardhat on Quaiscan is available here.

Remix

While there are 2 plugins available to help with this process, Etherscan and Flattener. Currently only Flattener works with Blockscout. You can use this plugin to flatten contracts and submit for verification as flattened source code. This is the recommended option.

We also include the Manual Standard Input JSON Method below the flattener instructions. This method is not recommended, but included since it is also a viable method.

Flattener Plugin

  1. Go to Plugin Manager and search for "flattener". Activate the plugin. \

  2. The plugin is now available in the lefthand menu. \

  3. Compile the contract you want to verify. \

  4. Return to the Flattener. The β€˜Flatten contract_name’ button should appear. Click the button. Flattened source code is copied onto the clipboard. \

  5. Go to Quaiscan and on the verification page choose the β€˜Via flattened source code’ method. \

  6. Paste the copied flattened source code into the β€˜Enter the Solidity Contract Code’ field. \

  7. Check that all info is correct and click the Verify and Publish button to verify your contract. Once verified, the code tab will include the βœ… icon and source code will be viewable.

Manual Standard Input Json with Remix

Standard input json is basically the raw file fed into the Solidity compiler on verification. There are some minor updates made regarding info the output compiler should return, but the main contract-related fields remain the same. This way, standard json allows you to specify the most subtle compiler settings, as well as to specify all source files.

It is quite cumbersome and tedious work, so it is preferable to use any of the above methods, however, we describe the process in more detail for those who want to use it.

For this tutorial, we will create standard json for the following contract:

1) Start by creating a template which will be filled with sources later. For this purpose, we will use a metadata file generated by the compiler. You can find it in the β€œCompilation Details” tab (ensure that correct contract is chosen).

Compilation Details β†’ Metadata

2) The only fields required for standard json input are β€œlanguage”, β€œsettings”, and β€œsources”. In addition, only content is needed for sources. Add it for each source and remove everything unnecessary.

Note that the only fields to fill in the contents for each source file. Everything else (including compiler settings) is already filled via the metadata file.

3) First, add the content for the main OpenZeppelinSample.sol file

4) Next, add the sources for @openzeppelin/contracts/access/Ownable.sol contract that is being imported. They can be found inside the .deps/npm/ directories, which will appear after contract compilation.

Copy the source code with the path used in imports:

5) The last source is a "../utils/Context.sol" imported from @openzeppelin/contracts/access/Ownable.sol. You can find it in the same .deps/npm directory.

Although import "../utils/Context.sol"; specifies a relative path, the absolute path is used in standard json, and can be found relative to @openzeppelin/contracts/access/Ownable.sol

6) Submit Standard JSON input for verification.

Last updated