Alfaz Sozib
Alfaz Sozib

Reputation: 65

Uncaught (in promise) Error: call revert exception

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??

Upvotes: 2

Views: 4044

Answers (3)

Bemnet16
Bemnet16

Reputation: 13

if you're running your smart contract locally (using Hardhat, for example), you need to configure MetaMask to connect to the localhost network (the network your Hardhat or other local Ethereum network is running on).

Here’s how you can do it

Steps to Add Localhost Network to MetaMask Open MetaMask and click on the network dropdown at the top of the MetaMask extension (usually it says “Ethereum Mainnet” or another default network).

  • Click Add Network at the bottom of the dropdown menu.

  • In the Network settings window, fill in the following:

  • Network Name: Localhost (or whatever name you'd like)

  • New RPC URL: http://127.0.0.1:8545 (this is the default URL for Hardhat's local network)

  • Chain ID: 1337 (this is the default Chain ID for Hardhat's local network)

  • Currency Symbol: ETH (this is the default symbol for Ethereum)

  • Block Explorer URL: (Optional) Leave this empty if not using a block explorer. Click Save.

Upvotes: 0

Jayath DeSilva
Jayath DeSilva

Reputation: 11

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.

Upvotes: 1

Petr Hejda
Petr Hejda

Reputation: 43571

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.

Upvotes: 1

Related Questions