uncaught(承诺)错误:调用还原异常[请参阅: https://links.ethers.org/v5-errors-call_exception](方法=“ name()”, data =“ 0x”,errorArgs = null,errorname = null,errorSignature = null, 原因= null,code = call_exception,版本= 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)
})
我正在尝试阅读合同,但是为什么我会遇到此错误?我该如何解决?
我收到相同的错误消息。问题是我没有从我的Localhost Hardhat中部署它。在Metamask钱包中,您必须确保已连接到正确的HardHat Localhost网络。
仅在以太坊主网上的指定地址上有合同。但是该地址没有在其他网络上持有任何合同。
由于您正在使用MetAmask或其他浏览器钱包扩展名发布的单击Add Network
在下拉菜单的底部。
在“网络设置”窗口中,填写以下内容: NETWORK名称:
localhost(或您想要的任何名称)
newrpc url:
http://127.0.0.1:8545(这是Hardhat本地网络的默认URL)
币种符号:
BlockExplorer URL:(可选)如果不使用Block Explorer,则将此空白保留。 单击“保存”