0

I am getting an error trying to call an existing smart contract function using call(). The error is "Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced." My code is below

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 = JSON.parse(data.result);
  let contract_address = '0x672C1f1C978b8FD1E9AE18e25D0E55176824989c';
  const contract = new web3.eth.Contract(contract_abi, contract_address);
  contract.methods.totalSupply().call()
    .then(result => {
      console.log('result', result);
    }).catch(err => {
      console.log('error: ', err);
    })
})

When I execute the same function using send() it works, however I need the return value of the function which is why I want to use call(). I am using ganache to set up a local test network which is working fine. Thanks!

  • 1
    Can you check if the contract deployed on the `0x672C...` address on the local Ganache network? Or is it on a different address (on the local network)? – Petr Hejda Oct 06 '21 at 21:31
  • Yes, that was the problem the contract was never on the local network. I was able to solve it by using the Infura API to set up access to the mainnet. Thanks a lot! – eth_developer Oct 07 '21 at 14:08

0 Answers0