When I deploy a contract with Truffle that has an import statement, and try to verify it on etherscan, my understanding is that I need to paste in the contents of the imported file.

I get an error on etherscan that the bytecodes of the concatenated and deployed files are not the same. The strange thing is that if I deploy the contract (with imports) on remix then the bytecode matches with the concatenated source file.


Here is a minimal example of contracts that exhibit this behaviour.

Combined.sol is the concatenated file, and Outer.sol contains the contract that is deployed.

Here is what I am doing that gets an error:

  1. Deploy Outer.sol with truffle
  2. Go to deployed contract address on etherscan
  3. Input the Concatenated.sol source code and hit verify

Error, bytecodes do not match.

More info

  • Using compiler 0.4.11 in remix and truffle.
  • Ubuntu 16.04.
  • On Kovan, not that it should matter.
  • Deployed contract
  • 1
    For me verification of concatenated contracts used to work like a charm. Can you provide the address of the deployed minimal example on the Kovan network so I can investigate the case? – Jakub Wojciechowski Jul 5 '17 at 13:04
  • @JakubWojciechowski Updated answer with address of deployed contract – Travis Jacobs Jul 5 '17 at 13:52
  • When verifying the code on Etherscan, have you tried both with and without optimizations enabled? – DeviateFish Jul 8 '17 at 5:35

Currently etherscan does not support verification of multifile contracts. But there is discussion on etherscan's reddit about this issue.

Concatenating files into one worked some time ago, but since version 0.4.7 Solidity includes hash of contract's metadata at the end of compiled contract. As this metadata contains file names and hashes, you may get the same bytecode after concatenating and compiling but this hash will be different.

I think motivation behind adding hash of this metadata to deployed contract is to make source verification automatic as each deployed contract contains swarm-link to sources, compiler version and compilation options.

| improve this answer | |
  • So basically the verification feature is pretty much useless since solidity 0.4.7 ? – Nikita Fuchs Nov 7 '17 at 10:17

I created truffle-plugin-verify to automate Truffle contract verification on Etherscan.

  1. Install the plugin with npm
npm install truffle-plugin-verify
  1. Add the plugin to your truffle.js or truffle-config.js file
module.exports = {
  /* ... rest of truffle-config */

  plugins: [
  1. Generate an API Key on your Etherscan account (see the Etherscan website)
  2. Add your Etherscan API key to your truffle config
module.exports = {
  /* ... rest of truffle-config */

  api_keys: {
    etherscan: 'MY_API_KEY'

After migrating your Outer contract to Kovan, you are able to verify it on Etherscan by running:

truffle run verify Outer --network kovan

More information can be found on the repository or in my article Automatically verify Truffle smart contracts on Etherscan.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.