contract/verifysourcecode - 验证合约源代码
使用contract模块的verifysourcecode方法,验证指定合约的源代码。 由于HTTP的GET方法可以携带的数据量有限,因此该方法仅支持POST方式调用。
API定义
POST /api
表单参数:
- module:contract
- action:verifysourcecode
- contractaddress:合约部署地址
- sourceCode:要验证的合约源代码
- contractname:合约名称
- compilerversion:solidity编译器版本
- optimizationUsed:是否启用了编译优化
- runs:无特殊情况的话,设置为200
- constructorArguments:合约构造函数参数
- libraryname1:合约依赖库1的名称
- libraryaddress1:合约依赖库1的地址
- libraryname2:合约依赖库2的名称
- libraryaddress2:合约依赖库2的地址
- libraryname3:合约依赖库3的名称
- libraryaddress3:合约依赖库3的地址
- libraryname4:合约依赖库4的名称
- libraryaddress4:合约依赖库4的地址
- libraryname5:合约依赖库5的名称
- libraryaddress5:合约依赖库5的地址
- libraryname6:合约依赖库6的名称
- libraryaddress6:合约依赖库6的地址
- libraryname7:合约依赖库7的名称
- libraryaddress7:合约依赖库7的地址
- libraryname8:合约依赖库8的名称
- libraryaddress8:合约依赖库8的地址
- libraryname9:合约依赖库9的名称
- libraryaddress9:合约依赖库9的地址
- libraryname10:合约依赖库10的名称
- libraryaddress10:合约依赖库10的地址
API返回值
返回一个JSON对象,主要字段如下:
- status:状态码,1为成功
- message:调用描述信息,OK为成功
- result:调用结果
示例代码
下面的代码使用jquery来调用verifysourcecode方法:
//Submit Source Code for Verification
$.ajax({
type: "POST", //Only POST supported
url: "//api.etherscan.io/api", //Set to the correct API url for Other Networks
data: {
apikey: $('#apikey').val(), //A valid API-Key is required
module: 'contract', //Do not change
action: 'verifysourcecode', //Do not change
contractaddress: $('#contractaddress').val(), //Contract Address starts with 0x...
sourceCode: $('#sourceCode').val(), //Contract Source Code (Flattened if necessary)
contractname: $('#contractname').val(), //ContractName
compilerversion: $('#compilerversion').val(), // see http://etherscan.io/solcversions for list of support versions
optimizationUsed: $('#optimizationUsed').val(), //0 = Optimization used, 1 = No Optimization
runs: 200, //set to 200 as default unless otherwise
constructorArguements: $('#constructorArguements').val(), //if applicable
libraryname1: $('#libraryname1').val(), //if applicable, a matching pair with libraryaddress1 required
libraryaddress1: $('#libraryaddress1').val(), //if applicable, a matching pair with libraryname1 required
libraryname2: $('#libraryname2').val(), //if applicable, matching pair required
libraryaddress2: $('#libraryaddress2').val(), //if applicable, matching pair required
libraryname3: $('#libraryname3').val(), //if applicable, matching pair required
libraryaddress3: $('#libraryaddress3').val(), //if applicable, matching pair required
libraryname4: $('#libraryname4').val(), //if applicable, matching pair required
libraryaddress4: $('#libraryaddress4').val(), //if applicable, matching pair required
libraryname5: $('#libraryname5').val(), //if applicable, matching pair required
libraryaddress5: $('#libraryaddress5').val(), //if applicable, matching pair required
libraryname6: $('#libraryname6').val(), //if applicable, matching pair required
libraryaddress6: $('#libraryaddress6').val(), //if applicable, matching pair required
libraryname7: $('#libraryname7').val(), //if applicable, matching pair required
libraryaddress7: $('#libraryaddress7').val(), //if applicable, matching pair required
libraryname8: $('#libraryname8').val(), //if applicable, matching pair required
libraryaddress8: $('#libraryaddress8').val(), //if applicable, matching pair required
libraryname9: $('#libraryname9').val(), //if applicable, matching pair required
libraryaddress9: $('#libraryaddress9').val(), //if applicable, matching pair required
libraryname10: $('#libraryname10').val(), //if applicable, matching pair required
libraryaddress10: $('#libraryaddress10').val() //if applicable, matching pair required
},
success: function (result) {
console.log(result);
if (result.status == "1") {
//1 = submission success, use the guid returned (result.result) to check the status of your submission.
// Average time of processing is 30-60 seconds
document.getElementById("postresult").innerHTML = result.status + ";" + result.message + ";" + result.result;
// result.result is the GUID receipt for the submission, you can use this guid for checking the verification status
} else {
//0 = error
document.getElementById("postresult").innerHTML = result.status + ";" + result.message + ";" + result.result;
}
console.log("status : " + result.status);
console.log("result : " + result.result);
},
error: function (result) {
console.log("error!");
document.getElementById("postresult").innerHTML = "Unexpected Error"
}
});