Contracts

Get Contract ABI for Verified Contract Source Codes​

Returns the Contract Application Binary Interface ( ABI ) of a verified smart contract.
Find verified contracts
βœ…
on our Verified Contracts Source Code page.
1
https://api-ropsten.etherscan.io/api
2
?module=contract
3
&action=getabi
4
&address=0x41c61A4A5298093b0de024962f048cC790b23F89
5
&apikey=YourApiKeyToken
Copied!
Try this endpoint in your browser
πŸ”—
​
Request
Response
Query Parameters
Parameter
Description
address
the contract address that has a verified source code
Sample Response
1
{
2
"status":"1",
3
"message":"OK",
4
"result":"[{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"name\":\"initialize\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"_size\",\"type\":\"uint32\"}],\"name\":\"isBlockSizeSupported\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"upgradeParameters\",\"type\":\"bytes\"}],\"name\":\"upgrade\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256[]\",\"name\":\"_proof\",\"type\":\"uint256[]\"},{\"internalType\":\"bytes32\",\"name\":\"_commitment\",\"type\":\"bytes32\"},{\"internalType\":\"uint32\",\"name\":\"_chunks\",\"type\":\"uint32\"}],\"name\":\"verifyBlockProof\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"
5
}
Copied!
A simple sample for retrieving the contractABI using Web3.js and Jquery to interact with a contract.
1
var Web3 = require('web3');
2
var web3 = new Web3(new Web3.providers.HttpProvider());
3
var version = web3.version.api;
4
5
$.getJSON('https://api-ropsten.etherscan.io/api?module=contract&action=getabi&address=0x2e150637263745DAC19e0BB90B4348154bCd811f', function (data) {
6
var contractABI = "";
7
contractABI = JSON.parse(data.result);
8
if (contractABI != ''){
9
var MyContract = web3.eth.contract(contractABI);
10
var myContractInstance = MyContract.at("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359");
11
var result = myContractInstance.memberId("0xfe8ad7dd2f564a877cc23feea6c0a9cc2e783715");
12
console.log("result1 : " + result);
13
var result = myContractInstance.members(1);
14
console.log("result2 : " + result);
15
} else {
16
console.log("Error" );
17
}
18
});
Copied!

Get Contract Source Code for Verified Contract Source Codes​

Returns the Solidity source code of a verified smart contract.
​
πŸ“©
Tip : You can also download a CSV list of verified contracts addresses of which the code publishers have provided a corresponding Open Source license for redistribution.
1
https://api-ropsten.etherscan.io/api
2
?module=contract
3
&action=getsourcecode
4
&address=0xF34FE09b190A05E7ED8d5911EEd19a2504e3Fcd4
5
&apikey=YourApiKeyToken
Copied!
Try this endpoint in your browser
πŸ”—
​
Request
Response
Query Parameters
Parameter
Description
address
the contract address that has a verified source code
Sample Response
1
{
2
"status":"1",
3
"message":"OK",
4
"result":[
5
{
6
"SourceCode":"// SPDX-License-Identifier: UNLICENSED\r\npragma solidity ^0.8.0;\r\n\r\n//ERC20 Token Standard Interface\r\ninterface ERC20Interface {\r\n // function totalSupply() public view returns (uint256);\r\n\r\n // function balanceOf(address tokenOwner) public view returns (uint256 balance);\r\n\r\n // function allowance(address tokenOwner, address spender) public view returns (uint256 remaining);\r\n\r\n function transfer(address to, uint256 tokens)\r\n external\r\n returns (bool success);\r\n\r\n function approve(address spender, uint256 tokens)\r\n external\r\n returns (bool success);\r\n\r\n function transferFrom(\r\n address from,\r\n address to,\r\n uint256 tokens\r\n ) external returns (bool success);\r\n\r\n //Transfer event - useful for consumers - part of erc20\r\n event Transfer(address indexed _from, address indexed _to, uint256 _value);\r\n\r\n //Approval event - useful for consumers-part of erc20\r\n event Approval(\r\n address indexed _owner,\r\n address indexed _spender,\r\n uint256 _value\r\n );\r\n}\r\n\r\n//ERC20 Token\r\ncontract DappToken is ERC20Interface {\r\n string public name; //token_name\r\n string public symbol; //token_symbol\r\n uint256 public TotalSupply; //read the total no. of tokens with default getter\r\n\r\n mapping(address => uint256) public BalanceOf; //read token balance of specific address\r\n mapping(address => mapping(address => uint256)) public Allowance;\r\n\r\n //constructor func.\r\n constructor(uint256 _initialSupply) {\r\n name = \"NK Token\"; //token_name\r\n symbol = \"NKT\"; //token_symbol\r\n BalanceOf[msg.sender] = _initialSupply; //ref. above mapping\r\n TotalSupply = _initialSupply; //set total no. of tokens\r\n }\r\n\r\n \r\n function transfer(address _to, uint256 _value)\r\n public\r\n override\r\n returns (bool success)\r\n {\r\n //exception if account doesn't have enough tokens\r\n require(BalanceOf[msg.sender] >= _value);\r\n\r\n //Transfer balance\r\n BalanceOf[msg.sender] -= _value; //deduct the value from msg.sender\r\n BalanceOf[_to] += _value; //increase the value of the receiver\r\n\r\n //Transfer event\r\n emit Transfer(msg.sender, _to, _value);\r\n\r\n //returns a boolean\r\n return true;\r\n }\r\n\r\n function approve(address _spender, uint256 _value)\r\n public\r\n override\r\n returns (bool success)\r\n {\r\n //update the allowance\r\n Allowance[msg.sender][_spender] = _value;\r\n\r\n //approve event\r\n emit Approval(msg.sender, _spender, _value);\r\n\r\n //returns a boolean\r\n return true;\r\n }\r\n\r\n\r\n\r\n function transferFrom(\r\n address _from,\r\n address _to,\r\n uint256 _value\r\n ) public override returns (bool success) {\r\n //_from has enough tokens i.e _value is always <= balanceOf[_from]\r\n require(_value <= BalanceOf[_from]);\r\n\r\n //require allowance is big enough to send tokens\r\n require(_value <= Allowance[_from][msg.sender]);\r\n\r\n //update the allowance\r\n Allowance[_from][msg.sender] -= _value;\r\n\r\n //change balance\r\n BalanceOf[_from] -= _value;\r\n BalanceOf[_to] += _value;\r\n\r\n //transfer event\r\n emit Transfer(_from, _to, _value);\r\n\r\n //returns a boolean\r\n return true;\r\n }\r\n}",
7
"ABI":"[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_initialSupply\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"Allowance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"BalanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"TotalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
8
"ContractName":"DappToken",
9
"CompilerVersion":"v0.8.0+commit.c7dfd78e",
10
"OptimizationUsed":"0",
11
"Runs":"200",
12
"ConstructorArguments":"00000000000000000000000000000000000000000000000000000000000f4240",
13
"EVMVersion":"Default",
14
"Library":"",
15
"LicenseType":"Unlicense",
16
"Proxy":"0",
17
"Implementation":"",
18
"SwarmSource":"ipfs://7fc7a87f54872cd88e1a65665b778063d4d04308cf3e42d6b1c01703a7c0ffd7"
19
}
20
]
21
}
Copied!

Verify Source Code

Submits a contract source code to Etherscan for verification.
See Demo Source Verification Submission Code at Source Code Verification Sample.
  1. 1.
    Requires a valid Etherscan API key, it will be rejected otherwise
  2. 2.
    Current daily limit of 100 submissions per day per user (subject to change)
  3. 3.
    Only supports HTTP POST due to max transfer size limitations for HTTP GET
  4. 4.
    Supports up to 10 different library pairs
  5. 5.
    Contracts that use "imports" will need to have the code concatenated into one file as we do not support "imports" in separate files.
  6. 6.
    List of supported solc versions, only solc version v0.4.11 and above is supported e.g. v0.4.25+commit.59dbf8f1
  7. 7.
    Upon successful submission you will receive a GUID (50 characters) as a receipt
  8. 8.
    You may use this GUID to track the status of your submission
  9. 9.
    Verified Source Codes will be displayed at the Verified Contracts page.

Source Code Submission Gist

​
πŸ‘‡
Note: Upon successful submission, a GUID is returned, which can be used to check for submission status.
1
//Submit Source Code for Verification
2
$.ajax({
3
type: "POST", //Only POST supported
4
url: "//api-ropsten.etherscan.io/api", //Set to the correct API url for Other Networks
5
data: {
6
apikey: $('#apikey').val(), //A valid API-Key is required
7
module: 'contract', //Do not change
8
action: 'verifysourcecode', //Do not change
9
contractaddress: $('#contractaddress').val(), //Contract Address starts with 0x...
10
sourceCode: $('#sourceCode').val(), //Contract Source Code (Flattened if necessary)
11
codeformat: $('#codeformat').val(), //solidity-single-file (default) or solidity-standard-json-input (for std-input-json-format support
12
contractname: $('#contractname').val(), //ContractName (if codeformat=solidity-standard-json-input, then enter contractname as ex: erc20.sol:erc20)
13
compilerversion: $('#compilerversion').val(), // see https://ropsten.etherscan.io/solcversions for list of support versions
14
optimizationUsed: $('#optimizationUsed').val(), //0 = No Optimization, 1 = Optimization used (applicable when codeformat=solidity-single-file)
15
runs: 200, //set to 200 as default unless otherwise (applicable when codeformat=solidity-single-file)
16
constructorArguements: $('#constructorArguements').val(), //if applicable
17
evmversion: $('#evmVersion').val(), //leave blank for compiler default, homestead, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul (applicable when codeformat=solidity-single-file)
18
licenseType: $('#licenseType').val(), //Valid codes 1-12 where 1=No License .. 12=Apache 2.0, see https://ropsten.etherscan.io/contract-license-types
19
libraryname1: $('#libraryname1').val(), //if applicable, a matching pair with libraryaddress1 required
20
libraryaddress1: $('#libraryaddress1').val(), //if applicable, a matching pair with libraryname1 required
21
libraryname2: $('#libraryname2').val(), //if applicable, matching pair required
22
libraryaddress2: $('#libraryaddress2').val(), //if applicable, matching pair required
23
libraryname3: $('#libraryname3').val(), //if applicable, matching pair required
24
libraryaddress3: $('#libraryaddress3').val(), //if applicable, matching pair required
25
libraryname4: $('#libraryname4').val(), //if applicable, matching pair required
26
libraryaddress4: $('#libraryaddress4').val(), //if applicable, matching pair required
27
libraryname5: $('#libraryname5').val(), //if applicable, matching pair required
28
libraryaddress5: $('#libraryaddress5').val(), //if applicable, matching pair required
29
libraryname6: $('#libraryname6').val(), //if applicable, matching pair required
30
libraryaddress6: $('#libraryaddress6').val(), //if applicable, matching pair required
31
libraryname7: $('#libraryname7').val(), //if applicable, matching pair required
32
libraryaddress7: $('#libraryaddress7').val(), //if applicable, matching pair required
33
libraryname8: $('#libraryname8').val(), //if applicable, matching pair required
34
libraryaddress8: $('#libraryaddress8').val(), //if applicable, matching pair required
35
libraryname9: $('#libraryname9').val(), //if applicable, matching pair required
36
libraryaddress9: $('#libraryaddress9').val(), //if applicable, matching pair required
37
libraryname10: $('#libraryname10').val(), //if applicable, matching pair required
38
libraryaddress10: $('#libraryaddress10').val() //if applicable, matching pair required
39
},
40
success: function (result) {
41
console.log(result);
42
if (result.status == "1") {
43
//1 = submission success, use the guid returned (result.result) to check the status of your submission.
44
// Average time of processing is 30-60 seconds
45
document.getElementById("postresult").innerHTML = result.status + ";" + result.message + ";" + result.result;
46
// result.result is the GUID receipt for the submission, you can use this guid for checking the verification status
47
} else {
48
//0 = error
49
document.getElementById("postresult").innerHTML = result.status + ";" + result.message + ";" + result.result;
50
}
51
console.log("status : " + result.status);
52
console.log("result : " + result.result);
53
},
54
error: function (result) {
55
console.log("error!");
56
document.getElementById("postresult").innerHTML = "Unexpected Error"
57
}
58
});
Copied!

Check Source Code Verification Submission Status

1
//Check Source Code Verification Status
2
$.ajax({
3
type: "GET",
4
url: "//api-ropsten.etherscan.io/api",
5
data: {
6
apikey: $('#apikey').val(),
7
guid: 'ezq878u486pzijkvvmerl6a9mzwhv6sefgvqi5tkwceejc7tvn', //Replace with your Source Code GUID receipt above
8
module: "contract",
9
action: "checkverifystatus"
10
},
11
success: function (result) {
12
console.log("status : " + result.status); //0=Error, 1=Pass
13
console.log("message : " + result.message); //OK, NOTOK
14
console.log("result : " + result.result); //result explanation
15
$('#guidstatus').html(">> " + result.result);
16
},
17
error: function (result) {
18
alert('error');
19
}
20
});
Copied!

Verify Proxy Contract

Submits a proxy contract source code to Etherscan for verification.
  1. 1.
    Requires a valid Etherscan API key, it will be rejected otherwise
  2. 2.
    Current daily limit of 100 submissions per day per user (subject to change)
  3. 3.
    Only supports HTTP post
  4. 4.
    Upon successful submission you will receive a GUID (50 characters) as a receipt
  5. 5.
    You may use this GUID to track the status of your submission
  6. 6.
    Verified proxy contracts will display the "Read/Write as Proxy" of the implementation contract under the contract address's contract tab

Verifying Proxy Contract using cURL

Request
Response
1
// example with only the mandatory contract address parameter
2
curl -d "address=0xcbdcd3815b5f975e1a2c944a9b2cd1c985a1cb7f" "https://api-ropsten.etherscan.io/api?module=contract&action=verifyproxycontract&apikey=YourApiKeyToken"
3
​
4
// example using the expectedimplementation optional parameter
5
// the expectedimplementation enforces a check to ensure the returned implementation contract address == address picked up by the verifier
6
curl -d "address=0xbc46363a7669f6e12353fa95bb067aead3675c29&expectedimplementation=0xe45a5176bc0f2c1198e2451c4e4501d4ed9b65a6" "https://api-ropsten.etherscan.io/api?module=contract&action=verifyproxycontract&apikey=YourApiKeyToken"
Copied!
1
// OK
2
{"status":"1","message":"OK","result":"gwgrrnfy56zf6vc1fljuejwg6pelnc5yns6fg6y2i6zfpgzquz"}
3
​
4
// NOTOK
5
{"status":"0","message":"NOTOK","result":"Invalid API Key"}
Copied!

Checking Proxy Contract Verification Submission Status using cURL

Request
Response
1
curl "https://api-ropsten.etherscan.io/api?module=contract&action=checkproxyverification&guid=gwgrrnfy56zf6vc1fljuejwg6pelnc5yns6fg6y2i6zfpgzquz&apikey=YourApiKeyToken"
Copied!
1
// OK
2
{"status":"1","message":"OK","result":"The proxy's (0xbc46363a7669f6e12353fa95bb067aead3675c29) implementation contract is found at 0xe45a5176bc0f2c1198e2451c4e4501d4ed9b65a6 and is successfully updated."}
3
4
// NOTOK
5
{"status":"0","message":"NOTOK","result":"A corresponding implementation contract was unfortunately not detected for the proxy address."}
Copied!
Last modified 3mo ago