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