How to verify a contract using thirdweb SDK

Which block explorers does verification work with?

 

Currently, contract verification works with any Etherscan-built block explorer. As a general rule of thumb, if the site ends in “scan” then it is compatible with this form of contract verification.

Unsure if your block explorer was built by Etherscan?

Here is a full list of compatible explorers https://etherscan.io/eaas

Step 1: Create an account

Once you have reached the explorer that services your chain, you will need to create an account in order to register an apiKey

Notion image
 

Step 2: Create an API Key

In order to use the thirdweb SDK contract verifier, you will need to have an API Key for the specific block explorer you are wanting to verify on. On your account profile (or account dropdown tab) click the API Keys tab, from there, we will add a new apiKey.

Notion image
Notion image

Give your apiKey a name and click continue


Step 3: Explorer API Url

Once we have our API key, we need an endpoint to send the request to. On the left-hand side of the dashboard, click the API Service link. Note this will be different for each explorer, so make sure you use the link from the dashboard for your chain.

Notion image

In this example, we are using Cronoscan, but your URL should be similar, when in doubt, ensure the endpoint begins and ends with API as pictured below:

Notion image
 

Step 4: Setup our project

Once we have our explorer API Url and our API Key, we need to add those to our script below. In addition to this, we now need to declare our contract type (If you are unsure of your contract type you can visit our docs here for more details)

import { getContract } from "thirdweb";
import { verifyContract } from "thirdweb/contract";
import { ethereum } from "thirdweb/chains";
import { createThirdwebClient } from "thirdweb";

const client = createThirdwebClient({
  clientId: "<your_client_id>",
});

const contract = getContract({
  // the client you have created via `createThirdwebClient()`
  client,
  // the chain the contract is deployed on
  chain: ethereum,
  // the contract's address
  address: "0x123...",
  // OPTIONAL: the contract's abi
  abi: [...],
});

const verificationResult = await verifyContract({
 contract,
 explorerApiUrl: "https://api.polygonscan.com/api",
 explorerApiKey: "YOUR_API_KEY",
});
console.log(verificationResult);
 

Step 5: Verify the contract

Once completed run:

node verify.js
 

That’s it, you should receive a confirmation for your contract verification


 

Can’t get this working? If you’ve followed the above and still have issues, contact our support team for help.

 
Did this answer your question?
😞
😐
🤩