3
votes

I am using Truffle to deploy a smart contract on the Rinkeby network. The smart contract contains an import of a library (Ownable).

I am trying to verify the contract on Etherscan but I am not able to :(

It seems that Truffle "flatten" the contract code but I can't find the actual output used to compile.

I checked the build folder and I can find the bytecode and deployedBytecode but not the "flatten" contract source.

Where can I find this information?

Deployment on Rinkeby:

michael$ truffle deploy --reset --network rinkeby
Using network 'rinkeby'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0xe179c58d10d66def5d26a06c89848b88c812458f1c2e92bcff40372e6c476f08
  Migrations: 0xa06c5370a513ad9aa25213db9610d77a9533c4c1
Saving successful migration to network...
  ... 0xaa08dbc87a185613854689ffe408e3dc441344191c52194d835124e37a2a4fd1
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Replacing BlockBetGameRegistry...
  ... 0x9bc7e990dc4ef9dd87f5c69c8a65b0e22cbcda10102abc7067fcfb451ca429bc
  BlockBetGameRegistry: 0x7be5198a14ff47815a85adc47bb5f1da31d352e6
Saving successful migration to network...
  ... 0xb942099bc2201d955bf60ce7ecba9edbe2f664b744f8543d43aa5588ff4d2f2f
Saving artifacts...

Contract code:

pragma solidity 0.4.18;

import 'zeppelin-solidity/contracts/ownership/Ownable.sol';

contract BlockBetGameRegistry is Ownable {
  address[] public games;

  event eventGameAdded(address game);

  function addGame (address _contractAddress) onlyOwner public {
    require(_contractAddress != address(0));
    games.push(_contractAddress);
    eventGameAdded(_contractAddress);
  }

  function numberOfGames () view public returns (uint256) {
    return games.length;
  }
}
2

2 Answers

1
votes

Unfortunately, Truffle does not yet support this. It is currently an open feature request (see the feature request). This seems to be a popular ask that the engineers behind Truffle believe in supporting, so it's probably just a matter of time before they implement it.

Until then, you have to use a utility that will flatten your code for you. There are 2 mentioned in the comments: sol-merger and truffle-flattener.

2
votes

As the other answer stated, there is no native Truffle functionality to help with this. However, the Truffle team did release plugin functionality early this year. So 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: [
    'truffle-plugin-verify'
  ]
}
  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 contract to to a public network, you are able to verify it on Etherscan by running:

truffle run verify ContractName [--network networkName]

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