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

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

我已经在 public 测试网上部署了一个智能合约,现在我正尝试使用 ethers js 从前端连接到它。但是当我尝试获取值时,它会在控制台中出现以下错误:

我在前端使用 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();
  }  
}

我遇到了同样的错误。一旦我将它部署到测试网络(之前我部署到本地主机),我就没有更改合约地址。 请检查您使用的合约地址是否是您部署到测试网的合约地址。

我遇到了同样的问题,检查一下:

  1. 合约地址正确
  2. 你调用的方法是正确的
  3. 参数正确

在我的例子中,我调用了一个不存在的方法。