[Ethereum] Checking whether a contract is verified on Etherscan or BSCscan through an API

contract-verificationexplorer-api

I've been trying to write a script to monitor new pairs created on Pancakeswap to see if there are tokens worth investing into. However I've noticed that 80% + of those are scams, and most of the time the contract is not verified on BSCscan or Etherscan.

I was wondering if there is a way to programmatically get whether a contract is verified so I can only notify myself of coins that at least have their source code verified to filter the new coins that are being listed.

What I've tried

I've tried the BSCscan API but it wasn't documented very well. I was looking at the Contract API and tried making an HTTP Get to it through Node.js. What I got in return wasn't useful. I used the following code to make a request to the contract API using a random address, please let me know if there is anything wrong.

const https = require('https')
const contract_address = '0x76c1d11e6b538ec5991ea47b8d109ca3b80df73b'
var url = `https://api.bscscan.com/api?module=contract&action=getabi&address=${contract_address}&apikey=${process.env.bscscan_api}`;


https.get(url, (response) => {
    console.log(response);
});

Question

I was wondering if there is any way to programmatically check whether a contract is verified on BSCscan or Etherscan through an API or perhaps using ethers.js or web3?

I think scrapping the website would also work but it would be great if anyone knows an API or resource for this!

I'm not familiar with solidity but I'm open to learning if there are any solidity solutions for this as well!

Thanks!

Best Answer

Ok I found out the answer to this question. Essentailly the API I specified above was the correct one. You just have to check the 'data' field.

If verified:

data.status = '1', and it has some other fields

If not verified:

data.status = '0' and data.result = 'Contract source code not verified'
Related Topic