1

Uncaught (in promise) Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="name()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)

const provider = new ethers.providers.Web3Provider(window.ethereum);
    const address = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
    const abi = [
        "function name() view returns (string)",
        "function symbol() view returns (string)",
        "function totalSupply() view returns (uint256)"
    ]
    const connectWallet =  (async()=>{
        await provider.send("eth_requestAccounts",[]);
    })
    const contract = new ethers.Contract(address,abi,provider);

    const getInfo = (async()=>{
        const n = await contract.name();
        console.log(n)
    })

I am trying to read the contract but why I am getting this error ? and how can i solve it??

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

1

I received the same error message. The problem was that I did not deploy that from my localhost hardhat. In your Metamask wallet, you must ensure that you are connected to the correct Hardhat localhost network.

0

There is a contract deployed on the specified address only on the Ethereum mainnet. But this address doesn't hold any contract on other networks.

Since you're using the window.ethereum provider published by MetaMask or another browser wallet extension, the call is sent on the network that is currently selected in the wallet.

So if you select the Ethereum mainnet, the call succeeds. In all other cases, the call fails because there is no contract on the selected network that could respond to the call.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • I get this when I'm connected to localhost in Metamask, but my localhost is running a mainnet fork of Ethereum so these contracts should all exist. Any ideas why an error like this occurs on forks of mainnet running locally? – Kyle B. May 08 '23 at 15:06