Verifying Contracts Programmatically
If you'd like to verify contracts via our website, you may do so using the Verify and Publish Source Code page.
Source code verification provides a way for projects to open source
🌍
their smart contract code for end users to inspect and verify that it does what it claims to do.
By uploading source code, Etherscan will match the compiled contract bytecode with that on the blockchain and display it under the Contract tab.
For repeated or multiple verification of contracts, it may be more productive to programmatically verify your contracts through an API endpoint
🎯
.
The tools needed to follow along with this guide is Postman, an API development application and a valid Etherscan API key.

1. Pointing API Endpoints

Point your API request URL to https://api.etherscan.io/api and set your request method to POST.
If you'd like to deploy this to any other testnet such as Rinkeby/Ropsten/Goerli, replace the request URL to your specific testnet API endpoint.

2. Setting API Keys & Module

Under the Request Body, set the format to x-www-form-urlencoded.
Include your API key under the apikey field, set the module to contract, and action to verifysourcecode.

3. Attaching Source Code

Paste your contract source code under the sourceCode parameter.
If your contract uses "imports", you will need to concatenate the code into one file ( otherwise known as "flattening" ) as we do not support "imports" in separate files.
Examples of Solidity flatteners that can be used are solidity-flattener by @BlockCatIO or SolidityFlattery by @DaveAppleton

4. Configuring Source Code Parameters

Configure the details of your deployed contract such as contractname, compilerversion, optimizationUsed and so on.
You have to specify the fields marked as required, and optional fields if applicable to your contract.
Parameter
Field
Description
contractaddress
Required
contract address, eg. 0x4c113f627fe35231fd11131a9974b9a99f584cb6
codeformat
Required
solidity-single-file by default, or solidity-standard-json-input
contractname
Required
contract name, eg HelloWorld
compilerversion
Required
compiler version used, eg. v0.7.6+commit.7338295f
see Etherscan's supported compilers<b></b>
optimizationUsed
Required
use 0 for no optimization, and 1 if optimization was used
runs
Optional
the no. of runs if optimization was used, eg. 200
constructorArguments
Optional
for contracts that were created with constructor parameters, using ABI encoding.
evmversion
Optional
leave blank for default compiler, specify if others such as tangerineWhistle, spuriousDragon, byzantium etc
licenseType
Optional
an integer between 1 - 12, see Open Source License Types for all options
default value of 1 indicating No License
libraryname
Optional
library used in contract, eg. SafeMath
supports up to 10 different libraries
libraryaddress
Optional
library address eg. 0xCfE28868F6E0A24b7333D22D8943279e76aC2cdc
a matching pair of libraryname - libraryaddress must be provided
The final body sample request using Bulk Edit in Postman will resemble this.
1
apikey:3KVM8TSNFSZT9B9DFTY9H1QJ1U1QJESNXB
2
module:contract
3
action:verifysourcecode
4
sourceCode:pragma solidity ^0.7.6;↵contract HelloWorl {↵ string public greet = "Hello Worl!";↵}
5
contractaddress:0x9Dca580D2c8B8e19e9d77345a5b4C2820B25b386
6
codeformat:solidity-single-file
7
contractname:HelloWorld
8
compilerversion:v0.7.6+commit.7338295f
9
optimizationused:1
10
runs:200
11
constructorArguements:0xfce353f66162630000000000000000000000000
12
evmversion://leave blank for compiler default
13
licenseType:1
14
libraryname1:SafeMath
15
libraryaddress1:0xCfE28868F6E0A24b7333D22D8943279e76aC2cdc
16
libraryname2://if applicable, matching pair required
17
libraryaddress2://if applicable, matching pair required
18
libraryname3://if applicable, matching pair required
19
libraryaddress3://if applicable, matching pair required
20
libraryname4://if applicable, matching pair required
21
libraryaddress4://if applicable, matching pair required
Copied!

5. Contract Verification Results

Upon sending your request, you should receive a GUID ( 50 characters ) as your submission receipt.
You may check the status of your source code verification using the "Check Source Code Verification Status" endpoint. The average processing time is between 30 - 60 seconds.
Upon successful verification
, users will be able to interact with your contract on Etherscan and it will be listed under the Verified Contracts page.
Last modified 7d ago