简体   繁体   English

MetaMask - RPC 错误:执行恢复 {code: -32000, message: 'execution reverted'} 在尝试连接到智能合约时

[英]MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'} while trying to connect to smart contract

I have deployed a smart contract on a public testnet and now I am trying to connect to it from the front end using ethers js.我已经在公共测试网上部署了一个智能合约,现在我正在尝试使用 ethers js 从前端连接到它。 But when I try to fetch the value it gives the following errors in the console:但是当我尝试获取该值时,它会在控制台中出现以下错误:

在此处输入图像描述

I am using Angular for the front end and here's the code I wrote:我在前端使用 Angular,这是我写的代码:

declare let window: any;
import { Component, OnInit } from '@angular/core';
import { ethers } from 'ethers';
import addresses from '../../environment/contract-address.json'
import Election from '../../blockchain/artifacts/blockchain/contracts/Election.sol/Election.json'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'angvote';
  public signer: any;
  public electionContract: any;
  public candidate : any;
  public candidatesList:string[] | undefined;
  constructor(){}

  async ngOnInit(){
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    window.ethereum.enable()
    
    provider.on("network",(newNetwork: any, oldNetwork: any)=>{
      if (oldNetwork){
        window.location.reload();
      }
    });

    this.signer = provider.getSigner();

    if(await this.signer.getChainId() !== 4){
      alert("Please change your network to Rinkeby!")
    }

    this.electionContract = new ethers.Contract(addresses.electioncontract,Election.abi,this.signer);
    this.candidate = await this.electionContract.candidatesCount();
  }  
}

I have encountered the same error.我遇到了同样的错误。 I had not changed the contract address once I deployed it to the testnet(Previously I deployed to localhost).将合约地址部署到测试网后,我没有更改合约地址(之前我部署到本地主机)。 Just check if the contract address you are using is of the contract you deployed to the testnet.只需检查您使用的合约地址是否是您部署到测试网的合约。

I met the same problem, check that:我遇到了同样的问题,请检查:

  1. the contract address is correct合约地址正确
  2. the method you call is correct你调用的方法是正确的
  3. the parameter is correct参数正确

in my case, I called an non-exist method.就我而言,我调用了一个不存在的方法。

I came across this problem and tried this solution and more but it didn't work.我遇到了这个问题并尝试了这个解决方案等等,但它没有用。 What solve it for me was making sure my contract address and abi file had the same version.为我解决的问题是确保我的合约地址和 abi 文件具有相同的版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MetaMask - RPC 错误:执行恢复{代码:-32000,消息:'执行恢复'} - MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'} 执行恢复{“originalError”:{“代码”:3,“数据”:,“消息”:“执行恢复”}} - execution reverted { "originalError": { "code": 3, "data": , "message": "execution reverted" } } 警告! 合约执行期间遇到的错误 [已恢复] - Warning! Error encountered during contract execution [Reverted] 在智能合约 Fundme 中出现错误,错误是“VM 执行错误。恢复为 0x” - Getting an error in smart contract Fundme, The error is "VM execution error. Reverted to 0x" tokenOfOwnerByIndexERC721 时执行恢复错误 - Execution reverted error while tokenOfOwnerByIndexERC721 从 next.js 调用智能合约时,RPC 错误:执行已恢复 - RPC Error: excution reverted" when calling smart contract from next.js Web3.js 返回错误:执行已恢复 - Web3.js returned error: execution reverted 'code': -32603, 'message': 'Error: Transaction reverted without a reason string' 当我尝试使用 swapExactTokensForTokens UNISWAP - 'code': -32603, 'message': 'Error: Transaction reverted without a reason string' while i'm trying to use swapExactTokensForTokens UNISWAP brownie:ValueError: execution reverted: VM Exception while processing transaction: revert - brownie:ValueError: execution reverted: VM Exception while processing transaction: revert web3 python getAmountsOut 执行已恢复 - web3 python getAmountsOut execution reverted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM