How to verify a evm contract through http api

1.Parameters to be prepared

Since different chains may require different parameters, let's use mainnet as an example.

1.1 api url

The API URL for mainnet is https://api.etherscan.io/api. If you are using a different chain, you will need to refer to the official documentation to find the corresponding API URL.

1.2 api key

First let's access to ethscan dashbord https://etherscan.io/myaccount, click the API Keys

and then click the ADD button to create a new api key

1.3 chain id

Get your target chain id from chainlist

1.4 contractaddress

After successfully deploying the contract, you can obtain the deployed contract address.

1.5 compilerversion

For my contract, we use Solidity version v0.8.24+commit.e11b9ed9 to compile the code.

1.6 constructorArguments

we should encode the constructor arguments

const args = abi.encode(["address", "string", "string", "uint256", "bytes32"], [sd, name, symbol, premintFormat, merkle]);

And we can use hashex to encode the constructor arguments online.

2.Send http request

After collecting all the required data, we can send it to the API server using axios.

axios.request(config)
.then((response) => {
    console.log(JSON.stringify(response.data));
})
.catch((error) => {
    console.log(error);
});

3.check the result on explorer

after successfully verify the contract , we can see the green icon on explorer website.

4.full code

check the full code from github gist gist

5.origin

oneclicktoken