Verifying your smart contract source code increases transparency and trust in your project. This guide outlines how to verify contracts on Subscan (applicable to Darwinia, Moonbeam, Astar, etc.), specifically focusing on how Remix users can modify the generated Metadata JSON to meet Subscan's verification requirements.
- Target Network: Darwinia
- Example Contract:
0x00000000001523057a05d6293c1e5171ee33ee0a - Tool: Remix IDE
Before verification, ensure your local compilation environment in Remix matches the settings used during the actual deployment exactly.
- Open your project in Remix.
- Attention to Paths: Ensure your file structure matches the
importstatements. - Example: Upload or edit
Quacks.sol.
- Navigate to the Solidity Compiler tab.
- Compiler Version: Select the exact version used for deployment (e.g.,
0.8.x). - EVM Version: If a specific version was used (e.g.,
paris,london), select it; otherwise, leave asdefault. - Optimization: Check
Enable optimizationand set theRunsvalue (commonly 200). This must match the deployment settings. - Click Compile Quacks.sol.
- After successful compilation, go to the File Explorer (left sidebar).
- Look inside the
artifacts/folder (or root directory depending on Remix version). - Locate the file named:
ContractName_metadata.json(e.g.,Quacks_metadata.json).
Subscan's "Standard JSON" verification method requires the full source code within the JSON file. However, the default metadata.json generated by Remix often contains URLs (IPFS/Swarm) instead of the actual source code content.
You must manually edit this JSON file to inject the source code.
Open Quacks_metadata.json. In the sources section, you might see a structure like this (missing actual code):
"sources": {
"Quacks.sol": {
"keccak256": "0x...",
"urls": ["bzz-raw://...", "dweb:/ipfs/..."] // Subscan cannot read these external links
}
}
You need to replace or add to the entry with a "content" field containing the actual Solidity source string.
Example of the Modified JSON Structure:
{
"language": "Solidity",
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
// ... other settings
},
"sources": {
// For the main file
"Quacks.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ncontract Quacks { ... PASTE FULL SOURCE CODE HERE ... }"
},
// For dependencies (e.g., OpenZeppelin) - EVERY imported file needs this
"@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts...\n... PASTE FULL LIBRARY SOURCE HERE ..."
}
}
}
💡 Tips:
- All imported files must be listed in
sources.- The value of
"content"must be a string (watch out for newlines\nand escaping quotes).- If you are using Hardhat/Foundry, their generated
build-infofiles already contain thecontentfield, so this manual step is not needed.
Save your modified JSON file locally as Standard-Input.json.
- Go to the Subscan Contract Verify Tool - Darwinia network as an example.
- in the Subscan explorer top navigation bar, select Tools → Contract Verification Tool.
- Verification Method: Select
Standard-JSON-Input. - Compiler Version: Select the version you used in Remix.
- Upload File: Upload the
Standard-Input.jsonyou created in Phase 2.
Click Verify. If the JSON format is correct and the compiled bytecode matches the on-chain bytecode, the verification will succeed.
After verification succeeds, search the contract address on the target network and open the Contract tab to:
- View Code (source + metadata)
- Use Read and Write to interact with the contract
- Example: : Contract Detail page - Darwinia network as an example
| Issue | Possible Cause & Solution |
|---|---|
| Bytecode mismatch | Optimization Runs: Did you use 200 runs in Remix but default in the JSON? Ensure they match. |
| EVM Version: Ensure the EVM version (e.g., London/Paris) is consistent. | |
| Parsing Error | JSON Syntax: Ensure the pasted source code in the JSON doesn't break the JSON string format (escape quotes " with \"). |
| Alternative Method | If manual JSON editing is too difficult, install the "Flattener" plugin in Remix. Flatten your code into one file, and use the "Flatten Code" method on Subscan instead. |
If you run into any issues, please reach out via:
- GitHub Issues (recommended): Open an issue in this repository so we can track and improve the guide.
- Telegram: https://t.me/+ldEA4oysskNiMzE1
- Email: api@subscan.io
Security note: Please do not share private keys, seed phrases, or sensitive credentials in public issues or chats.