Etherscan.io has a Verify Contract Code feature that takes the inputs Solidity Contract Code and Constructor Arguments ABI-encoded.

Question: Is there a tool to flatten your solidity contracts (written in conjunction with the use of Truffle), and maybe even generate the ABI-encoded constructor arguments, so as to speed up your use of Etherscan's contract verification feature?

Tried Blockcat's python script solidity-flattener but could never get it to work. Hoping to discover a new alternative method.

  • My code compiles, but I still cannot create a flatfile. Any suggestions? <pre> user@eth:/code/myproject$ truffle compile user@eth:/code/myproject$ touch contracts/CtdToken.sol user@eth:/code/myproject$ truffle compile Compiling ./contracts/CtdToken.sol... Compiling ./contracts/InterfaceUpgradeAgent.sol... Compiling ./contracts/UpgradableToken.sol... Compiling ./contracts/Withdrawable.sol... Compiling zeppelin-solidity/contracts/lifecycle/Pausable.sol... Compiling zeppelin-solidity/contracts/math/SafeMath.sol... Compiling zeppelin-solidity/contracts/ownership/Ownable.sol... Compiling zeppelin-s
    – NFN_NLN
    Jan 15 '18 at 1:40

I've used this one in the past, with very good results and minimal setup: https://github.com/oraclesorg/oracles-combine-solidity

git clone https://github.com/oraclesorg/oracles-combine-solidity
cd oracles-combine-solidity
npm install
npm start "path_to_not_flat_contract_definition_file.sol"
  • Much quicker option
    – Lismore
    Aug 10 '18 at 14:46

I use this which is built to work with Truffle specifically and it works great, although it's early in its development: https://github.com/alcuadrado/truffle-flattener


Try to use


Here is example from my case

solidity_flattener contracts/MyTicketSale.sol --solc-paths=zeppelin-solidity=$(pwd)/node_modules/zeppelin-solidity/ --output result.sol

Hope this helps


I've just released a simple-to-install Solidity Flattener - https://github.com/bokkypoobah/SolidityFlattener

  • 1
    If you, like I did, tried Blockcat's solidity-flattener and failed to get it working, try this tool. It really works!
    – Evgeniy
    May 29 '19 at 15:21

Truffle Flattener

Yes, there is truffle-flattener (https://github.com/nomiclabs/truffle-flattener/) that combines all your smart contracts files into one. And it works well with Truffle. Here is how to use it:

1) Install globally:

npm install -g truffle-flattener

2) Use it, for example, to flatten your smart contract 'SimpleToken.sol' like this:

truffle-flattener contracts/SimpleToken.sol > FlattenedSimpleToken.sol

(Simple step by step tutorial to use truffle flattener and verify your code manually on etherscan.io: https://www.sitepoint.com/flattening-contracts-debugging-remix/)

Verify with OpenZeppelin SDK

However, if you like to do a fully automated etherscan.io verification, there is openzeppelin verify And here is how to use it: https://forum.openzeppelin.com/t/verify-with-openzeppelin-sdk/1206


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

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.