How to Verify Smart Contracts on Etherscan

Want to quickly build a web UI for your smart contracts? Etherscan can do that for you! Read on to learn how to verify your Solidity smart contracts on Etherscan.

📬 Get updates straight to your inbox.

Subscribe to my newsletter so you don't miss new content.

Use Plugins If You Can

This guide shows you how to verify contracts manually. There are better alternatives now.

Are you on Truffle? Use this Truffle plugin to automatically verify after every deploy.

On Buidler instead? Use the buidler-etherscan plugin.

You can now skip the rest of the article.

Manual Guide

First, you’ll need it to flatten your Solidity contract into a single file for Etherscan. This means merging your files and their dependencies in the right order.

Flatten your Solidity contract

Install truffle-flattener or sol-merger.

npm install truffle-flattener -g

Navigate into your Truffle project, and run truffle-flattener. You can copy the results to your clipboard with pbpaste:

truffle-flattener contracts/MyToken.sol | pbpaste

Verifying on Etherscan

Go to your contract’s Etherscan page. Click ‘Verify and Publish’:

Etherscan

Select the ‘Solidity (Single file)’ Compiler Type and your Soliditty Compiler Version (e.g. 0.5.11). Press Continue:

Etherscan

Paste in your flattened Solidity contract.

Etherscan

Your constructor arguments should be filled automatically. Otherwise, go to the transaction hash of your contract deployment and retrieve it. Each argument supplied to the constructor is ABI-encoded and looks something like: 00000000000000000000000022bc795b5b8154fe619724e7cb1f4b931cd39c11.

If you’ve enabled optimization in your Truffle configuration, be sure to specify ‘Optimization’ and ‘Runs’ to match those settings.

Etherscan

In Closing

That’s it! You now have a handy web UI you can use to read and write against your smart contracts at etherscan.io/dapp/<contract address>.

Etherscan