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

0

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.

Browse other questions tagged or ask your own question.