0

I am trying to get the contract ABI using the Etherscan API, and then create a contract instance and call a method using web3.js. I am able to get the ABI from Etherscan but when creating the contract object I am getting this error: "You must provide the json interface of the contract when instantiating a contract object." This is what my code looks like

let url = 'https://api.etherscan.io/api?module=contract&action=getabi&address=0x672C1f1C978b8FD1E9AE18e25D0E55176824989c&apikey=<api-key>';
request(url, (err, res, body) => {
  if (err) {
    console.log(err);
  }
  let data = JSON.parse(body);
  let contract_abi = data.result;
  console.log(contract_abi)
  let contract_address = '0x672C1f1C978b8FD1E9AE18e25D0E55176824989';
  const contract = new web3.eth.Contract(contract_abi);
  const contract_instance = contract.at(contract_address);
  // Call contract method
})

When I console.log the contract_abi I see the ABI data. I've also tried creating the contract by doing

const contract = new web3.eth.Contract(contract_abi, contract_address)

Thanks!

1 Answer 1

0

looks like you have a typo, the address ends with a 'c' in the url, but not in let contract_address=...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.