Portal pentru dezvoltatori
Temă

Verify Contract Source Code#

By uploading the contract source code, X Layer explorer will match the compiled contract bytecode with the bytecode on the blockchain and display it on the contract page of the explorer.

You can use this endpoint to quickly verify contracts and improve verification efficiency. The average processing time for contract verification is between 30-60 seconds.

Request Path#

POST
https://web3.okx.com/api/v5/xlayer/contract/verify-source-code

Request Parameters#

ParameterTypeRequiredDescription
chainShortNameStringYesThe abbreviated name of the blockchain network, e.g, XLAYER
contractAddressStringYesContract address
contractNameStringYesContract name
sourceCodeStringYesSource code of the contract. 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. You can use Solidity flatteners like SolidityFlattery(by@DaveAppleton)
codeFormatStringYesCode format, we support solidity-single-file, solidity-standard-json-input, vyper
compilerVersionStringNoCompiler version used, e.g., v0.7.6+commit.7338295f, vyper:0.2.11. You can check the supported compiler versions for contract verification in the X Layer Explorer under the Verify Contract sectionWhen the codeFormat is solidity-standard-json-input, it is optional; otherwise, it is required.
optimizationStringNoWhether optimization was used when compiling the contract, 0 for no optimization, 1 if optimization was usedWhen the codeFormat is solidity-standard-json-input, it is optional; otherwise, it is required.
optimizationRunsStringNoThe number of runs if optimization was used, e.g., 200
contractAbiStringNoContract ABI
evmVersionStringNoEVM version of contract compilation, leave blank for default compiler, specify if others such as tangerineWhistle, spuriousDragon, byzantium
licenseTypeStringNoOpen source license type, leave blank for default No License
viaIrBolNoWhether to introduce an IR-based code generator, should be consistent with your compiling setting; true / false, false by default
libraryInfoArrayNoLibrary info used in contract. The libraryName and libraryAddress must be matched one by one. We support up to 10 different libraries.
> libraryNameStringNoLibrary name
> libraryAddressStringNoLibrary address, e.g., 0xCfE28868F6E0A24b7333D22D8943279e76aC2cdc

Response Parameters#

ParameterTypeDescription
guidStringA GUID is returned upon successful submission, which can be used to query the verification result

Request Example#

shell
curl --location --request POST 'https://web3.okx.com/api/v5/xlayer/contract/verify-source-code' \
--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z' \
--header 'Content-Type: application/json' \
--data '{
    "chainShortName":"XLAYER",
    "contractAddress":"0x9Dca580D2c8B8e19e9d77345a5b4C2820B25b386",
    "contractName":"HelloWorld",
    "sourceCode":"pragma solidity ^0.7.6;↵contract HelloWorl {↵ string public greet = '\''Hello Worl!'\'';↵}",
    "codeFormat":"solidity-single-file",
    "compilerVersion":"v0.7.6+commit.7338295f",
    "optimization":"1",
    "optimizationRuns":"200",
    "contractAbi":"0xfce353f66162630000000000000000000000000",
    "evmVersion":"tangerineWhistle",
    "viaIr":false,
    "libraryInfo":[
        {
            "libraryName":"libraryName1",
            "libraryAddress":"0xCfE28868F6E0A24b7333D22D8943279e76aC2cdc"
        },
        {
            "libraryName":"libraryName2",
            "libraryAddress":"0xCfE28868F6E0A24b7333D22D8943279e76aC2cdc"
        },
        {
            "libraryName":"libraryName3",
            "libraryAddress":"0xCfE28868F6E0A24b7333D22D8943279e76aC2cdc"
        }
    ]
}'

Response Example#

json
{
    "code": "0",
    "msg": "",
    "data": [
        "eb5c06099d3841359d398541166343fe"
    ]
}