Snowtrace is currently working on a new user interface (UI) for smart contract verification. Meanwhile, you may consider using their API for a seamless smart contract verification experience.
Ensure you have Postman or any other API platform installed on your computer (or accessible through online services), along with your contract's source code and the parameters utilized during deployment.
Here is the API call URL to use for a POST request: https://api.snowtrace.io/api?module=contract&action=verifysourcecode
Please note that this URL is specifically configured for verifying contracts on the Avalanche C-Chain Mainnet. If you intend to verify on the Fuji Testnet, use: https://api-testnet.snowtrace.io/api?module=contract&action=verifysourcecode
Here's the body of the API call with the required parameters:
{ "contractaddress": "YOUR_CONTRACT_ADDRESS", "sourceCode": "YOUR_FLATTENED_SOURCE_CODE", "codeformat": "solidity-single-file", "contractname": "YOUR_CONTRACT_NAME", "compilerversion": "YOUR_COMPILER_VERSION", "optimizationUsed": "YOUR_OPTIMIZATION_VALUE", // 0 if not optimized, 1 if optimized "runs": "YOUR_OPTIMIZATION_RUNS", // remove if not applicable "licenseType": "YOUR_LICENSE_TYPE", // 1 if not specified "apikey": "API_KEY_PLACEHOLDER", // you don't need an API key, use a placeholder "evmversion": "YOUR_EVM_VERSION_ON_REMIX", "constructorArguments": "YOUR_CONSTRUCTOR_ARGUMENTS" // Remove if not applicable}
This part of the tutorial assumes that the contract was deployed using Hardhat and that all Hardhat dependencies are properly installed to include '@nomiclabs/hardhat-etherscan'.
You will need to create a .env.json with your Wallet Seed Phrase. You don't need an API key to verify on Snowtrace.
Example .env.json:
.env.json
{ "MNEMONIC": "your-wallet-seed-phrase",}
Below is a sample hardhat.config.ts used for deployment and verification:
hardhat.config.ts
import { task } from "hardhat/config"import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"import { BigNumber } from "ethers"import "@typechain/hardhat"import "@nomiclabs/hardhat-ethers"import "@nomiclabs/hardhat-waffle"import "hardhat-gas-reporter"import "@nomiclabs/hardhat-etherscan"import { MNEMONIC, APIKEY } from "./.env.json"// When using the hardhat network, you may choose to fork Fuji or Avalanche Mainnet// This will allow you to debug contracts using the hardhat network while keeping the current network state// To enable forking, turn one of these booleans on, and then run your tasks/scripts using ``--network hardhat``// For more information go to the hardhat guide// https://hardhat.org/hardhat-network/// https://hardhat.org/guides/mainnet-forking.htmlconst FORK_FUJI = falseconst FORK_MAINNET = falseconst forkingData = FORK_FUJI ? { url: "https://api.avax-test.network/ext/bc/C/rpc", } : FORK_MAINNET ? { url: "https://api.avax.network/ext/bc/C/rpc", } : undefinedtask( "accounts", "Prints the list of accounts", async (args, hre): Promise<void> => { const accounts: SignerWithAddress[] = await hre.ethers.getSigners() accounts.forEach((account: SignerWithAddress): void => { console.log(account.address) }) })task( "balances", "Prints the list of AVAX account balances", async (args, hre): Promise<void> => { const accounts: SignerWithAddress[] = await hre.ethers.getSigners() for (const account of accounts) { const balance: BigNumber = await hre.ethers.provider.getBalance( account.address ) console.log(`${account.address} has balance ${balance.toString()}`) } })export default { etherscan: { // Your don't need an API key for Snowtrace }, solidity: { compilers: [ { version: "0.8.0", }, { version: "0.8.10", }, ], }, networks: { hardhat: { gasPrice: 225000000000, chainId: 43114, //Only specify a chainId if we are not forking // forking: { // url: 'https://api.avax.network/ext/bc/C/rpc', // }, }, fuji: { url: "https://api.avax-test.network/ext/bc/C/rpc", gasPrice: 225000000000, chainId: 43113, accounts: { mnemonic: MNEMONIC }, }, mainnet: { url: "https://api.avax.network/ext/bc/C/rpc", gasPrice: 225000000000, chainId: 43114, accounts: { mnemonic: MNEMONIC }, }, },}
Once the contract is deployed, verify with hardhat verify by running the following:
You can also verify contracts programmatically via script. Example:
verify.ts
import console from "console"const hre = require("hardhat")// Define the NFTconst name = "MockNFT"const symbol = "Mock"const _metadataUri = "ipfs://QmQ2RFEmZaMds8bRjZCTJxo4DusvcBdLTS6XuDbhp5BZjY"const _maxTokens = "100"async function main() { await hre.run("verify:verify", { address: "0x3972c87769886C4f1Ff3a8b52bc57738E82192D5", constructorArguments: [name, symbol, _metadataUri, _maxTokens], })}main() .then(() => process.exit(0)) .catch((error) => { console.error(error) process.exit(1) })
First create your script, then execute it via hardhat by running the following:
npx hardhat run scripts/verify.ts --network fuji
Verifying via terminal will not allow you to pass an array as an argument, however, you can do this when verifying via script by including the array in your Constructor Arguments. Example: