0

enter image description here

when i click "Wave at me" button i encounter with this call revert error!.

here is the App.js

import React, { useEffect, useState } from "react";
import { ethers } from "ethers";
import './App.css';
import abi from './utils/WavePortal.json';

const App = () => {
  const [currentAccount, setCurrentAccount] = useState("");
  
  const contractAddress = "0xe50fc795e586B9Cd2f888142EBE5Fb9e59a26812";
  const contractABI = abi.abi;
  const getEthereumObject = () => window.ethereum;
  
  const checkIfWalletIsConnected = async () => {
    try {
      const { ethereum } = window;

      if (!ethereum) {
        console.log("Make sure you have metamask!");
        return;
      } else {
        console.log("We have the ethereum object", ethereum);
      }

      const accounts = await ethereum.request({ method: 'eth_requestAccounts' });

      if (accounts.length !== 0) {
        const account = accounts[0];
        console.log("Found an authorized account:", account);
        setCurrentAccount(account)
      } else {
        console.log("No authorized account found")
      }
    } catch (error) {
      console.log(error);
    }
  }

  const connectWallet = async () => {
    try {
      const  ethereum  = getEthereumObject();

      if (!ethereum) {
        alert("Get MetaMask!");
        return;
      }

      const accounts = await ethereum.request({ method: "eth_requestAccounts" });

      console.log("Connected", accounts[0]);
      setCurrentAccount(accounts[0]); 
    } catch (error) {
      console.log(error)
    }
  }

  const wave = async () => {
    try {
      const { ethereum } = window;

      if (ethereum) {
        const provider = new ethers.providers.Web3Provider(ethereum);
        const signer = provider.getSigner();
        const wavePortalContract = new ethers.Contract(contractAddress, contractABI, signer);

        var count = await wavePortalContract.getTotWaves();
        console.log("Retrieved total wave count...", count.toNumber());

        const waveTxn = await wavePortalContract.wave();
        console.log("Mining...", waveTxn.hash);

        await waveTxn.wait();
        

        console.log("Mined -- ", waveTxn.hash);

        count = await wavePortalContract.getTotWaves();
        console.log("Retrieved total wave count...", count.toNumber());
      } else {
        console.log("Ethereum object doesn't exist!");
      }
    } catch (error) {
      console.log(error)
    }
  }

  useEffect(() => {
    checkIfWalletIsConnected();
  }, [])
  

  return (
    
    <div className="mainContainer">
      

      <div className="dataContainer">
        <div className="header">
        <h1>👋</h1>
        <h2> Hey folks!</h2> 
        </div>

        <div className="bio">
        This is Dinesh! I am learning web3 and currently working on projects with the help of buildSpace. Connect your Ethereum wallet and wave at me!
        </div>

        <button className="waveButton" onClick={wave}>
          <h3>Wave at Me</h3>
        </button>

        {!currentAccount && (
          <button className="waveButton" onClick={connectWallet}>
            <h3>Connect Wallet</h3>
          </button>
        )}
      </div>
     
    </div>  
      
  );
  }
export default App;
1
  • That message means the contract has generated an error in the getTotWaves function.
    – Ismael
    Jan 13 at 5:27

1 Answer 1

0

I believe the problem is that you did not switch to the Goerli test network via the MetaMask.

1
  • I encountered a similar error, and I found that switching my Metamask to the Goerli test network was indeed the solution for me. It's essential to ensure that the correct network is selected in Metamask when working with decentralized applications. By sharing our experiences, we can help others troubleshoot and find solutions more effectively. I appreciate your input, and I believe checking the network settings in Metamask can be valuable advice for anyone facing a similar error.
    – DirtyPeta
    Jun 14 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.