Contract Verification Export: Cronoscan To Cronos Explorer
Last updated
Was this helpful?
Last updated
Was this helpful?
As a developer, you may have submitted your smart contract code to a blockchain explorer (e.g., Cronoscan) as part of your smart contract deployment script. You can also submit it to other platforms for verification (e.g., Cronos Explorer).
This guide explains how to export data from one explorer and upload it into another. However, this only works for one smart contract at a time.
Cronoscan provides an endpoint for registered users to retrieve contract source code and compilation settings:
The parameters are as follows:
YourContractAddress: address of your smart contract on Cronos EVM chain.
YourApiKeyToken: API key on the Cronoscan platform.
The output may look like this (example from this contract: https://cronoscan.com/address/0x7de56bd8b37827c51835e162c867848fe2403a48#code)
The endpoint's response includes the following fields:
ContractName: Name of contract
CompilerVersion: Version name of compiler for contact
ConstructorArguments: Argument inputs used when creating the contract
OptimizationUsed: the value is "1" if optimization was used when compiling this contract
Runs: Number of times the optimization was run
SourceCode: The source code field's value must be reformatted first. See the instructions below.
The source code field's value may be provided in one of the three following formats:
In this case, you need to create a .JSON file by following these steps:
Remove the outer brackets "{" and "}"
"Unescape" the JSON string. This means replacing the backslashed characters with non-backslashed characters. You can use various tools for this, such as freeformatter (click: Unescape JSON).
Paste the resulting string into a new JSON file that you can name, for example, source_code.json. The JSON file should now be in this format.
In this case, you need to create a .SOL file. Copy the code and paste it into a new solidity file that you can name, for example, source_code.sol.
In this case, you need to create a .JSON file by following these steps:
"Unescape" the JSON string (Once only). This means replacing the backslashed characters with non-backslashed characters. You can use various tools for this, such as freeformatter (click: Unescape JSON).
Create a new JSON file that you can name, for example, source_code.json, using the template below:
In the JSON file that you just created, update the "enabled" and "runs" values to match the OptimizationUsed (where 1 should be converted to true) and Runs values from the Cronoscan response.
Paste the unescaped JSON string into the JSON file, where "**Paste here**" is a placeholder for where you should insert the unescaped JSON string obtained in the previous step.
Please visit the Cronos Explorer User Interface, which looks like this:
You can use the elements from Step 1 to complete the corresponding inputs:
Contract Name: Refer to the ContractName field from the Cronoscan response.
Contract Address: Address of the contract.
Compiler Type: there are two possible scenarios, depending on the format of the source code file generated in Step 2.
Scenario 1: The source code is a Solidity file (such as source_code.sol), generated from a SourceCode value in Source code-only format with a single source file. In that case:
Compiler Type: select Solidity Files.
Contract Files: Upload the solidity file (.sol) generated in Step 2.
Optimizer Enabled: Toggle yes if the OptimizationUsed field from the Cronoscan response is 1.
Optimizer Runs: If Optimizer Enabled is toggled, use the value from the Runs field in the Cronoscan response.
Scenario 2: The source code is a JSON file (such as source_code.json) generated from a SourceCode value either in Standard JSON input format or in Source code-only format with multiple source files. In that case:
Compiler Type: select Solidity Standard-Json-Input.
Check and, if necessary, edit the value of the JSON file as follows:
Double check the value of the settings.optimizer.enabled
field. It must be set to true if the OptimizationUsed field from the Cronoscan response is 1. If there is a mismatch, fix it manually in the source_code.json file.
Double check the value of the settings.optimizer.runs
field. It must be set to match the value of the Runs field from the Cronoscan response. If there is a mismatch, fix it manually in the source_code.json file.
Contract Files: Upload the JSON file (.json) generated in Step 2.
Compiler Version: Use the value of the CompilerVersion field from the Cronoscan response.
Constructor Arguments: Use the ConstructorArguments field from the Cronoscan response.
An example of the completed form is shown below:
After submitting the form, you are done!
If you encounter errors, please email contact@cronoslabs.org, making sure that you:
Specify the address of the smart contract.
Attach the JSON or SOL file generated in Step 2.
Attach a screenshot of the verification form you completed.
Most of the time, the errors are caused by mistakes when generating the JSON or SOL source code file.