It seems that there is (still) no straight way to verify your solidity contracts on etherscan.io
. Truffle makes it easy to build and deploy real
solidity projects. Splitting code into multiple files is a good practice but using imports
makes it difficult to verify your contracts on etherscan
because you have to provide all your contract's source code as a single file. I use npm
libraries to build solidity contracts so you can imagine that it's extreamly difficult to collect all source code.
Truffle could procide a new command verify
or export
which would build additional files needed for verification proces on etherscan.io
.
This sounds like a great idea! I'll add it to our internal tracking. Thanks!
Whoops. Closing the issue wasn't what I intended. Reopened.
This is a wonderful feature that is very useful.
I've tried multiple times in the past to verify contracts I wrote with Truffle, and it was an absolute hassle; The only times I was able to do so, was when I side-stepped Truffle's deployment pipeline, and manually flattened the source, followed by manually uploading it using Mist or Parity.
I see this as a must-have for any serious smart-contract project. 🙂
I would love this feature - I'm actually trying to include a flattener into my scripts now so that I always deploy flattened files so I always can verify the solidity. That will let me develop with separate files but not have to worry about tracking down what Solidity was compiled.
The really frustrating part of this process is that change comments, spacing, or anything about your Solidity results in different binary. You need exactly what was deployed - there's really no way around it.
Better yet, it would be nice if truffle verify [--network net]
actually made the calls to the etherscan API for the deployed contracts/network to verify the code. I found truffle-flattener to be the best tool for flattening source files, because it is aware of imports coming from npm modules.
I agree @moodysalem - Truffle Flattener still has issues but the team is working on making it easier and easier to use every day. It's what I use but it's still not ideal.
@mtbitcoin is it possible for you to expose an API for verifying your contracts? A package that combines truffle-flattener and a call to the etherscan API would be trivial to write
Would love to see this soon!
I'm using: https://www.npmjs.com/package/truffle-flattener
Also helpful when exporting to Remix
for debugging purposes.
This issue can be closed since truffle-flattener
does the trick.
@xpepermint @stefek99 I can try this again, but truffle-flattener did not do the trick at the time of posting this issue. Truffle flattener got close but not close enough to map perfectly to Etherscan, not to mention it was impossible to integrate into an automated workflow to run automatically as changes were made.
sol-merger works a treat. I used yesterday and will merge all your deps into one file and it works for deploying to etherscan code. Would be lovely to integrate this into build flow by way of a switch or something.
There is also https://github.com/BlockCatIO/solidity-flattener
Would be good to put a list of flatenners that work. I know the blockcat one does.
We can then put together a formal list which would be helpful
No need a list, just one that works is fine.
This issue has been funded using FundRequest. A developer can claim the reward by submitting a pull request referencing this issue. (How to Close Issues via Pull Requests?) e.g. fixes #564
I just funded this from FundRequest, we verify our contracts everytime we do a deploy. If the process could be simpler/faster it would be a time saver 👍
Despite original issue was about building additional files needed for verification proces on etherscan.io, I think Truffle could go a step further, and instead actuall call etherscan API for verfication. Ideally it would do so for every deployed contract (i.e. in deployer), subject to config option (as I guess some people may prefer not to share source code).
It is at the position to do so, it just deployed a contract, it knows the source code, it knows compiler version, so making human do the work is suboptimal.
@burdakovd Completely agree with you as I've had the some thoughts for over a year now.
Any update on getting a true 1 for 1 Truffle Deployed Smart Contract source code file to verify on etherscan?
For reference the API endpoint for the source code verification is available at https://etherscan.io/apis#contracts
This is a great candidate for a truffle run
plugin, which is part of the Truffle v5 release. See the release notes section about this feature, and stay tuned for more updates to come.
Good callout @mtbitcoin, I found that link earlier today when doing some research since it's been awhile since I looked for a solution last time. Couple that with truffle run
as @gnidan suggested would be awesome to see.
I'm going to start work on implementing this within Validity Labs toolchain (to be opensource in the future)
We’ve been running that api endpoint for quite a while. It is stable and should have 100% compatibility with the manual source verification on Etherscan (minus the error messages and some input checking). It does however require an api-key which can be generated for free on Etherscan.io
Ping if you have questions
Hi all. I'm closing this issue as out-of-scope, since, as mentioned, truffle run
should help solve this problem, in addition to the other tools mentioned above. Looking forward to seeing best practices emerge here. Thank you all!
@mtbitcoin I tried pretty much every flattener and can't get verification to work. What is the currently recommended way/tool? I'm using solidity 0.5.
@JohannesMayerConda if the flattened code compiles in Remix it should also work with ours
@mtbitcoin truffle-flattener works for me and compiles in remix but it doesn't verify. Their Readme also states
If you deploy your contracts with truffle's migrations the output of truffle-flattener may not match while verifying it in Etherscan
I opened an issue for Flattery https://github.com/akombalabs/SolidityFlattery/issues/2 where I'm stuck
And BlockCatIO/solidity-flattener has open issues like this BlockCatIO/solidity-flattener#26 and does strange things like putting a very old pragma version in the file
Is the solution to get rid of truffle migrations? What is good/best practice? Still the BlockCatIO solidity-flattener that has latest commit Dec 13, 2017?
I started work on a truffle plugin to automatically verify source code for deployed truffle contracts. The syntax is currently like this:
truffle run verify SimpleStorage --network rinkeby
Which automatically calls the Etherscan API and returns Pass - Verified
or Fail - Unable to verify
.
The functionality is still very limited and it doesn't support code flattening yet, so any kinds of contributions to the plugin are welcome!
I've been working on my own flavor that uses truffle-flattener
to flatten the files.
The offset feature, is that you'll need to deploy the contract(s) as how they are flattened. (Remix)
So using truffle to deploy said contracts is a no go unless we can secure 100% deterministic flattening across tools.
With that, I'll write up a small deployer tool that can used along with the flattener and verify-er.
Won't be a truffle plugin, but a separate NPM package that anyone can use along side of the development toolset.
Buidler also has an empty (from last week) repo that's titled to give the impression they are working on ethercan contract verification automation as well.
I found a nice
npm
package called sol-merger that does this pretty well. We could join forces with author.