For a complete list of resources regarding verification visit How to verify a contract on Etherscan/BscScan/PolygonScan.
The recommended way to verify a smart contract inheriting from OpenZeppelin Contracts is as a "multi-file" contract (corresponding to the Standard-Json-Input compiler type on Etherscan). It is easier to read, imports are maintained, licenses are maintained.
Verified using Hardhat
Verified using Truffle
Hardhat
Hardhat has an Etherscan plugin: Hardhat Etherscan plugin
Note: Hardhat was previously Buidler.
You can also use Hardhat to verify on BSCscan, see: https://docs.binance.org/smart-chain/developer/deploy/hardhat-verify.html
- Install the plugin
npm install --save-dev @nomiclabs/hardhat-etherscan
- Configure the plugin in
hardhat.config.js
Addrequire("@nomiclabs/hardhat-etherscan");
Add Etherscan API key ( keep secret and don't commit to version control)
Set compiler version to match what was deployed
// hardhat.config.js
const { infuraProjectId, mnemonic, etherscanApiKey } = require('./secrets.json');
require('@nomiclabs/hardhat-ethers');
require("@nomiclabs/hardhat-etherscan");
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
networks: {
rinkeby: {
url: `https://rinkeby.infura.io/v3/${infuraProjectId}`,
accounts: {mnemonic: mnemonic}
},
ropsten: {
url: `https://ropsten.infura.io/v3/${infuraProjectId}`,
accounts: {mnemonic: mnemonic}
},
kovan: {
url: `https://kovan.infura.io/v3/${infuraProjectId}`,
accounts: {mnemonic: mnemonic}
},
goerli: {
url: `https://goerli.infura.io/v3/${infuraProjectId}`,
accounts: {mnemonic: mnemonic}
},
mainnet: {
url: `https://mainnet.infura.io/v3/${infuraProjectId}`,
accounts: {mnemonic: mnemonic}
}
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: etherscanApiKey
},
solidity: "0.6.12"
};
- Verify
Remove any unnecessary contracts and clear the artifacts otherwise these will also be part of the verified contract.
npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
To verify SimpleToken (below) deployed on Rinkeby (https://rinkeby.etherscan.io/address/0x0bB0e851Da4f0149C7c3f77ac3492C824F1f4dD0#code) I ran the following:
$ npx hardhat verify --network rinkeby 0x0bB0e851Da4f0149C7c3f77ac3492C824F1f4dD0
Nothing to compile
Successfully submitted source code for contract
contracts/SimpleToken.sol:SimpleToken at 0x0bB0e851Da4f0149C7c3f77ac3492C824F1f4dD0
for verification on etherscan. Waiting for verification result...
Successfully verified contract on etherscan
Truffle
Truffle has an Etherscan plugin: truffle-plugin-verify
You can also use Truffle to verify on BSCscan, see: * https://docs.binance.org/smart-chain/developer/deploy/truffle-verify.html
You need to deploy with Truffle to verify with the Truffle verify plugin.
- Install the plugin
npm install -D truffle-plugin-verify
- Configure the plugin in
truffle-config.js
// truffle-config.js
...
const { infuraProjectId, mnemonic, etherscanApiKey } = require('./secrets.json');
const HDWalletProvider = require('@truffle/hdwallet-provider');
module.exports = {
...
networks: {
...
rinkeby: {
provider: () => new HDWalletProvider(
mnemonic, `https://rinkeby.infura.io/v3/${infuraProjectId}`
),
network_id: 4,
gasPrice: 10e9,
skipDryRun: true
},
ropsten: {
provider: () => new HDWalletProvider(
mnemonic, `https://ropsten.infura.io/v3/${infuraProjectId}`
),
network_id: 3,
gasPrice: 10e9,
skipDryRun: true
},
kovan: {
provider: () => new HDWalletProvider(
mnemonic, `https://kovan.infura.io/v3/${infuraProjectId}`
),
network_id: 42,
gasPrice: 10e9,
skipDryRun: true
},
goerli: {
provider: () => new HDWalletProvider(
mnemonic, `https://goerli.infura.io/v3/${infuraProjectId}`
),
network_id: 5,
gasPrice: 10e9,
skipDryRun: true
}
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: "0.6.12", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: "byzantium"
// }
}
},
plugins: [
'truffle-plugin-verify'
],
api_keys: {
etherscan: etherscanApiKey
}
};
- Verify
npx truffle run verify SomeContractName AnotherContractName --network networkName
To verify SimpleToken (below) deployed on Goerli (https://goerli.etherscan.io/address/0x27Bb3535432DE5351f7f892aDF99085f9cfCbfcb#code) I ran the following (from the project I used to deploy SimpleToken):
$ npx truffle run verify SimpleToken --network goerli
Verifying SimpleToken
Pass - Verified: https://goerli.etherscan.io/address/0x27Bb3535432DE5351f7f892aDF99085f9cfCbfcb#contracts
Successfully verified 1 contract(s).
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, 10000000 * (10 ** uint256(decimals())));
}
}