Verify smart contract inheriting from OpenZeppelin Contracts

The current best way to verify a smart contract inheriting from OpenZeppelin Contracts is using the Buidler Etherscan plugin

  1. Install the plugin
npm install --save-dev @nomiclabs/buidler-etherscan
  1. Configure the plugin in buidler.config.js
    Add usePlugin("@nomiclabs/buidler-etherscan");
    Add Etherscan API key (keep secret and don’t commit to version control)
    Set compiler version to match what was deployed
// buidler.config.js
const { projectId, mnemonic, apiKey } = require('./secrets.json');

usePlugin("@nomiclabs/buidler-etherscan");
usePlugin('@nomiclabs/buidler-ethers');

module.exports = {
    networks: {
        mainnet: {
          url: `https://mainnet.infura.io/v3/${projectId}`,
          accounts: {mnemonic: mnemonic}
        }
      },
    
    etherscan: {
        // Your API key for Etherscan
        // Obtain one at https://etherscan.io/
        apiKey: apiKey
      },
    solc: {
        version: "0.6.12"
      }
};
  1. Verify
    :warning: Remove any unnecessary contracts and clear the artifacts otherwise these will also be part of the verified contract.
npx buidler verify --network mainnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"

To verify SimpleToken (below) deployed on Ropsten (https://ropsten.etherscan.io/address/0xf7bb58740a1d5964286c376ac03ad282cf40fe69#code) I ran the following:

$ npx buidler verify --network ropsten 0xf7bb58740a1d5964286c376ac03ad282cf40fe69
Compiling...
Downloading compiler version 0.6.12
Successfully submitted source code for contract
contracts/SimpleToken.sol:SimpleToken at 0xf7bb58740a1d5964286c376ac03ad282cf40fe69
for verification on etherscan. Waiting for verification result...
Successfully verified contract on etherscan

SimpleToken.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

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

/**
 * @title SimpleToken
 * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `ERC20` functions.
 */
contract SimpleToken is ERC20 {

    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    constructor() public ERC20("SimpleToken", "SIM") {
        _mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
    }
}