A tutorial that teaches how to verify a smart contract using Basescan APIs.
src
folder will contain a Counter.sol
file which will serve as the contract you want to deploy.
Counter.sol
contract using forge create --rpc-url $BASE_RPC_URL --private-key $PRIVATE_KEY src/Counter.sol:Counter
Once deployed, it should return something like this:
Deployed to: 0xEF5fe818Cb814E5c8277C5F12B57106B4EC3DdaA
). Copy this address as you will need it in the next step.
API Keys
on the left navigation bar.
API Key Token
.js
file to create a function to that will call the Basescan’s contract verification endpoint.
In your terminal create a new file: touch verifyContractBasescan.js
then open this file in your IDE of choice.
At the top of the file create a variable that contains the Counter.sol
that was created from your foundry project.
async
function to call the basescan api. Basescan offers a few endpoints to interact with their api with the base url being: https://api.basescan.org/api
To verify a contract you will use the verifysourcecode
route, with the contract
module, and your apiKey
as query parameters.
.json
file that contains the contracts metadata and ABI. For this particular project, this information is located in the /verify_contracts/out/Counter.sol/Counter.json
Under the Metadata
object you will find the compiler version under evmversion
try-catch
block to send the request and log any errors to the console.
Your final file should look something like this:
node verifyContractBasescan.js
in your terminal
If successful, your terminal will output JSON text with three properties status
, message
and result
like below:
result
field