Yos Riady optimize for learning

How to Verify Smart Contracts on Etherscan

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.


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.

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’:


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


Paste in your flattened Solidity contract.


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.


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>.



You should follow me on Twitter.

📬 Get updates straight to your inbox.

Subscribe to my newsletter to make sure you don't miss anything.

Here's something you might be interested in...

Going Serverless book

Going Serverless teaches you how to build scalable applications with the Serverless framework and AWS Lambda. You'll learn how to design, develop, test, deploy, and secure Serverless applications from planning to production.

Learn more →