Skip to main content

Contract Verification

Once you have deployed your smart contracts, you can verify them on the explorer. The following guide uses hardhat.

Via Flattened Source Code

  1. Use the following command to get a flattened source code of your smart contract:
npx hardhat flatten path/to/your/contract.sol
  1. Find your deployed contract on the Kava explorer and follow the steps to verify. Make sure you import the contract .sol files as well as a metadata.json file for verification

Via Standard-JSON-input file

  1. Find your standard-json-input file or generate one from the artifacts/build-info/{hash}.json file. An example is shown below
{
"language": "Solidity",
"sources": {
"contracts/Storage.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.19;\n\ncontract Storage {\n uint public storage_box;\n\n function store(uint _value) public {\n storage_box = _value;\n }\n\n function retrieve() public view returns (uint) {\n return storage_box;\n }\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
}
  1. Upload the standard-input-json file to the explorer to verify your contract

Via Hardhat Verification Plugin

You can also verify directly from your Hardhat development environment. This requires the hardhat-etherscan plugin. The Kava explorer uses cosmostation API which is compatible with the Hardhat Etherscan plugin.

  1. Install the Hardhat Etherscan plugin, ensuring that the version is v3.1.0 or higher.
  2. Ensure your hardhat.config.js file includes the following etherscan configuration:
hardhat.config.js
module.exports = {
networks: {
kava: {
url: 'https://evm.kava.io',
},
},
etherscan: {
apiKey: {
kava: "9MgwdOWmMs", //"api key is not required by the Kava explorer, but can't be empty",
},
customChains: [
{
network: 'kava',
chainId: 2222,
urls: {
apiURL: 'https://api.verify.mintscan.io/evm/api/0x8ae',
browserURL: 'https://kavascan.com',
},
},
],
},
};
  1. Verify that the custom network is configured correctly, by checking if kava is listed in the supported custom networks.
$ npx hardhat verify --list-networks

Networks supported by hardhat-etherscan:

...

Custom networks added by you or by plugins:

╔═════════╤══════════╗
║ network │ chain id
╟─────────┼──────────╢
║ kava │ 2222
╚═════════╧══════════╝
  1. Verify the contract with npx hardhat ignition verify <deployment-id>. This may take a few minutes. The following is an example of verifying a Storage contract.
$ npx hardhat ignition verify chain-2222

Verifying contract "contracts/Storage.sol:Storage" for network kava...
Successfully verified contract "contracts/Storage.sol:Storage" for network kava:
- https://kavascan.com/address/0xa8E48Fa04881DFacfC8d0aB84BC9bA57A449fc1F#code

Troubleshooting

Here are some common errors and things to look out for when verifying your contracts.

Bytecode does not match, please try again.

Ensure the following options are the exact same as what you deployed with, then try again.

  • Compiler version
  • Optimization runs
  • ABI-encoded constructur arguments

There was an error compiling your contract: Multiple SPDX license identifiers found in source file

Flattening your contracts may sometimes merge multiple dependent contracts also with SPX identifiers (e.g. // SPDX-License-Identifier: GPL-3.0).

Remove all SPDX comments except one in your flattened file and try verifying again. Alternatively, use the hardhat verification plugin to preserve license identifiers.

Limitations

  • Contracts with ' can't be verified, to fix remove any ' from your contract before submitting it for verification
  • Contracts with flattened source code greater than 65000 characters can't be verified

Resources