8

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
4

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
4

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

3

Try to use

--solc-paths=zeppelin-solidity=$(pwd)/node_modules/zeppelin-solidity/

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

2

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 at 15:21
1

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