A contract verification script that leverages Sourcify's latest v2 API endpoints.
Hardhat-verify plugin is inconsistent and does not work all the time. This script uses custom logic to verify contracts by interacting with the Sourcify v2 API, by:
- compiling the contracts
- extracting the metadata
- copying the source files into a temporary directory
- submitting the verification job
- polling the verification job
- handling the verification status
The scripts supports only VeChain Mainnet and Testnet.
Run the script from the project root.
# Using the convenient yarn scripts
yarn contracts:verify:mainnet <contract-address> <contract-name># Verify StargateNFT on testnet (exact_match)
yarn contracts:verify:testnet 0x1234567890123456789012345678901234567890 StargateNFT
# Verify NodeManagementV3 on mainnet (exact_match)
yarn contracts:verify:mainnet 0x1234567890123456789012345678901234567890 NodeManagementV3--partial-match- If exact_match verification fails, try match verification (metadata-only)
When dealing with upgradeable contracts, you will need first to verify the Proxy contract by using the address of the proxy (that you use to interact with the contract) and the name of the proxy contract, eg: StargateProxy.
Then you need to verify the implementation contract code, so you will need to find the implementation address (from sourcify, vechainstats, or by looking at the Upgraded events in the contract) and the name of the implementation contract, eg: StargateNFT.
For projects using libraries, you will also need to verify each library contract.
- Make sure the contract has been compiled (
yarn contracts:compile)
- Try using the
--partial-matchflag (uses "match" instead of "exact_match") - Ensure you're using the same compiler version and settings as when the contract was deployed
- Check if the contract was deployed with constructor parameters
- It could take up to 24h for VeChainStats to replicate the verification from Sourcify into their database.
This means the source file missing (even if it's in the temp folder) has been modified since the contract was compiled, so the verification fails because Sourcify can't reproduce the same bytecode that was originally compiled.