This is a quick, 5-minute tutorial on how to verify your solidity contracts, written using truffle, on etherscan.io.

Navigate to your contract

First of all, navigate to your contract on the chain. It can be found at https://etherscan.io/address/YOUR_HASH#code

Navigate to Verify and Publish to go to the correct verification page.

We’ll need to add some extra parameters, which can only be enabled by pointing your the url to a different endpoint. Change “contractVerify” to “contractVerify2” in your url.

Fill in the correct values

Next up, you’ll need to fill in the correct values in the form. Enter the contract name you wish to verify. Choose the correct compiler. You can find the correct compiler by opening a new terminal and entering the following command.

solc — version

The result will most likely be a non-nightly build.

The correct value for Runs, which is the amount of times the optimization should run, is either 0 or 200, depending on your truffle version. With newer versions, we recommend trying with 200 first.

Paste the contents of your contracts in the code box. Keep the code as it was when you deployed it, but remove all the imports, as all code will be in a single file, so importing will not be necessary or supported.

Tip: We recommend using this tool to flatten your code. What oracles-combine-solidity does it get your contract code, import every contract your contract uses and flatten it all into one file. It will make your life a lot easier.

If you deployed a contract which contained constructor arguments, you’ll need to add them in the following input box. Constructor arguments are expected to be ABI-encoded. More information on ABI-encoding can be found on the page, but remember arguments are _right to left_. An example for one of our projects can be found below.

Tip: If you can’t figure out your ABI-encoded constructor arguments, first look at the encoded unlinked binary of your contract, then look at the encoded transaction-arguments of the transaction that created your contract. If your contract was deployed with constructor arguments, they should have been appended to the transaction data. So the difference between the two will be the ABI-encoded constructor arguments.

Lastly, you’ll need to add any libraries you’re using. You can find the location of your Libraries in the output of Truffle when you deployed them or in the generated json files.

That’s it, hit verify and publish. Your contract should now be verified. Your code should be visible on your contract and methods for reading the state of your contract will be available on the web page.

Why verify your contracts?

The reason we always verify our contracts is easy. First of all, it generates trust. People can see your contracts and verify the code with what you claim they should be doing.

Secondly, it’s darn useful to have an easy go-to page to read the state of your contracts.