in

Error when calling read function with Ethers.js HELP!!

I’m getting a:

`Error: call revert exception (method=”balanceOf(address)”, errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.4.0)`

Whenever I call a read-only function using Ethers.js. I’ve been looking everywhere for hours & I can’t figure out why it’s not working. It lets me send write transactions, but I can’t make a simple read-only call.

“`solidity
async function enableEth() {
if (window.ethereum) {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const [account] = await ethereum.request({
method: ‘eth_requestAccounts’
});
const signer = provider.getSigner(account);
const contract = new ethers.Contract(
contractAddress,
contractABI,
signer
);

const result = await contract.balanceOf(
‘0x5FbDB2315678afecb367f032d93F642f64180aa3’
);
console.log(result);
}
}
“`

What do you think?

10 Points
Upvote Downvote

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

2 Comments

  1. Either the address is wrong or the ABI is wrong or the network provider is wrong (which is actually just the address being wrong but worded differently).

    It is very possible your provider is pointing to a network you are not meaning it to. Try adding in logic to double check the chainId of the provider, and when starting a local hardhat always start it with a weird chainId. Make sure that’s the chainId from the provider.

Nexo Instant Crypto-Backed Loans now in 45+ Currencies in 200+ Jurisdictions | by Nexo | Nexo

SteelCase (SCS)- Hospital and Office Steel furniture. Dividend stock with upcoming ex/EFF date. Still under pre-pandemic price.