Verifying Contracts
Verify contract source code on the BattleChain block explorer
Overview
Verifying a contract publishes its source code on the block explorer so anyone can read, audit, and interact with it. Verified contracts display a checkmark badge and expose a Contract tab with the full source, ABI, and constructor arguments.
Why Verify
- Transparency — whitehats and the community can review your code directly on the explorer
- Trust — verified source proves the deployed bytecode matches your published code
- Debugging — the explorer's zkEVM debugger can map execution traces back to source lines for verified contracts
Verify with Forge
If you're deploying via Foundry, you can verify without leaving the terminal using forge verify-contract:
forge verify-contract <CONTRACT_ADDRESS> <PATH>:<CONTRACT_NAME> \
--chain-id 627 \
--verifier-url https://block-explorer-api.testnet.battlechain.com/api \
--verifier custom \
--etherscan-api-key "1234" \
--rpc-url https://testnet.battlechain.com:3051
Replace <CONTRACT_ADDRESS> with your deployed address and <PATH>:<CONTRACT_NAME> with the source path and contract name (e.g., src/MyVault.sol:MyVault).
| Flag | Value | Notes |
|---|---|---|
--chain-id | 627 | BattleChain testnet |
--verifier-url | https://block-explorer-api.testnet.battlechain.com/api | BattleChain explorer API |
--verifier | custom | Required when using a non-Etherscan explorer |
--etherscan-api-key | "1234" | Not validated — any non-empty string works |
--rpc-url | https://testnet.battlechain.com:3051 | BattleChain testnet RPC |
On success you'll see:
Start verifying contract `0x...` deployed on 627
Submitting verification for [src/MyVault.sol:MyVault] 0x...
Submitted contract for verification:
Response: `OK`
GUID: `<guid>`
URL: https://block-explorer-api.testnet.battlechain.com/address/0x...
The URL in the response links directly to the contract's verified page on the explorer.
If your contract has constructor arguments, add --constructor-args $(cast abi-encode "constructor(type,...)" arg1 arg2) to the command.
Verification Form
Navigate to /contracts/verify or click Verify Contract from any unverified contract page.
Required Fields
Contract Address — the deployed contract address to verify.
Compiler Type — choose one:
| Type | Use When |
|---|---|
| Solidity (single file) | Flattened single .sol file |
| Solidity (multi-part) | Multiple .sol files (standard project layout) |
| Vyper (JSON) | Vyper contracts with JSON input |
Compiler Version — select the exact version used to compile the contract. The dropdown shows all available versions.
EVM Version — the EVM target (e.g., london, paris). Select "Custom" to enter a specific version string.
Optimization — whether optimization was enabled during compilation, and if so, how many optimizer runs.
Contract Name — the name of the main contract (e.g., MyVault).
Source Code
- Single file: Paste the flattened Solidity source into the built-in editor
- Multi-file: Upload your source files and select the main contract file
Optional Fields
Constructor Arguments — the ABI-encoded constructor arguments used at deployment. Required if the contract's constructor takes parameters.
Submit
Click Verify. The explorer compiles your source with the specified settings and compares the resulting bytecode against what's deployed. If they match, the contract is verified immediately.
If compilation fails, the explorer shows the compiler errors so you can correct your input.
What Verified Contracts Show
Once verified, the contract's address page gains a Contract tab containing:
- Source code — full syntax-highlighted source with line numbers
- ABI — the contract's JSON ABI
- Compilation details — compiler version, optimization settings, EVM version
- Constructor arguments — decoded if provided
The Events tab also benefits from verification — event names and parameter types are decoded rather than shown as raw hex topics.