solc-sjw
has been renamed to solt. Read the accompanying blogpost.
It is a well known fact that the hardest part of being a solidity developer is verifying your deployed contracts on etherscan. (See here, here, here, and here)
As a defi veteran (8 months and counting), I've had countless nightmarish encounters with verifying contracts on etherscan. Now that I've emerged victorious from the battle field, I would like to share my experiences, and a new tool made by my good friend hjubb on verifying your contracts on etherscan, 100% of the time, 99.99% of the time.
One of the most common verification methods is to flatten your contracts after compilation and deployment and verify the flatten contracts.
This works on simple contracts, but on more complicated contracts where pragma experimental ABIEncoderV2
is being used, the location and presence of that declaration changes the output bytecode significantly. This is demonstrated here.
More concretely, if:
A.sol
, and B.sol
A.sol
contains ABIEncoderV2
and was compiled with standard frameworks, B.sol
's generated bytecode will be compiled without ABIEncoderV2
.A.sol
and B.sol
were to be flatten, ABIEncoderV2
will be present in both files, resulting in a different bytecode.There are also other suspects, such as truffle compiling contracts with absolute filepaths, resulting in a different swarmhash when compiled on a different machine (etherscan has however stated that it shouldn't affect anything).
Fortunately, there is another format the etherscan verification process supports – the standard json format.
It looks something like:
{
"language": "Solidity",
"sources": {
"contracts/ContractA.sol": {
"content": "<SOURCE_CODE A>"
},
"contracts/ContractB.sol": {
"content": "<SOURCE_CODE B>"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
}
}
}
This input format allows us to verify contracts that spans across multiple files without needing to flatten them.
solc-sjw
stands for solc-standard-json-writer. It is a static binary written in Kotlin-Native (tm) that helps you format your solidity contracts into the standard input format. Its written by my good friend hjubb, and you can find the source code here.
solc-sjw
has been renamed to solt. Read the updated blogpost for more information
In this example, we'll walk through an example on how to generate a standard input json format, and verify it on etherscan.
git clone https://github.com/iearn-finance/yearn-protocol.git
cd yearn-protocol
solt write contracts
# A new file called solc-input-contracts.json should be present in the current working directory
Solidity: Standard-Json-Input
as the verification method.solc-input.json
click, click, click…And it should be verified now.
Tl;dr: standard json good.
Have fun verifying!