Since the answer to this post is old. I figured I'd give an updated, programmatic way to verify contracts on Etherscan using Truffle and Brownie.
For both Truffle and Brownie, you will need to make an account on Etherscan and obtain an API token. It's important that you add it as an enviroment varbiable in a .env file.
Using Brownie:
Your enviroment variable should look like:
export ETHERSCAN_TOKEN=0000000000000000000000000000000000
In your contract deployment script, add a verify source parameter and set it to true. It should look something like below.
def deploy_token():
account = get_account()
token_contract = ERC20Token.deploy(
"MyTokenName",
"TOKENSYMBOL",
{"from": account},
publish_source=True
)
When you run your deployment script, your contract will be automatically verified, and you will see a verification message in your console.
Using Truffle:
You will need to download the dependency npm install truffle-plugin-verify. Then, add this to your truffle-config.js:
plugins: [
"truffle-plugin-verify"
],
api_keys: {
etherscan: process.env.ETHERSCAN_API_KEY
}
Note: This assumes you have already obtained your Etherscan token and added it to your .env file as an environment variable.
Once your contract is deployed to a network, run the command:
truffle run verify yourContract --network nameOfNetwork
Also, if anyone knows an easy way to verify contracts using Hardhat, please add an answer below. It would be nice to have all this info in one place.
I'm still learning this stuff too, so if someone has a more efficient way of verifying contracts, please let me know.