0

The sendTransaction is the function I call when trying to send a GoETH from one metaMask account to the other . The problem is that when I try to acces the getTransactionCount it gives me the error Error: Call revert exception.

My contract is deployed succesfully because the function addToBlockchain works perfectly. But this certain method does not. Does it has to do with the return type or parameters ? Also when I try the getAllTransactions triggers the same error.

import React,{useEffect,useState} from 'react';
import {ethers} from 'ethers';
import {contractAbi,contractAddress} from '../utils/constant';


const {ethereum}=window;
const createEthereumContract=()=>{
    const provider = new ethers.providers.Web3Provider(ethereum);
  const signer = provider.getSigner();
  const transactionsContract = new ethers.Contract(contractAddress, contractAbi, signer);

 

   return transactionsContract;
}


const sendTransaction=async()=>{
        try {
        
        
        const { addressTo, amount, keyword, message } = formData;
        const transactionsContract = createEthereumContract();
        const parsedAmount = ethers.utils.parseEther(amount);

        await ethereum.request({
          method: "eth_sendTransaction",
          params: [{
            from: currentAccount,
            to: addressTo,
            gas: "0x5208",
            value: parsedAmount._hex,
          }],
        });

        const transactionHash = await transactionsContract.addToBlockchain(addressTo, parsedAmount, message, keyword);

        setIsLoading(true);
        console.log(`Loading - ${transactionHash.hash}`);
        await transactionHash.wait();
        setIsLoading(false);
        console.log(`Success - ${transactionHash.hash}`);
        

    
        const transactionCount=await transactionsContract.getTransactionCount();
       

        setTransactionCount(transactionCount.toNumber());
        // window.location.reload();

        console.log(parsedAmount);
        } catch (error) {
            console.log(error);

        }
    }

My smart contract code in solidity looks like this:

// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

//import "hardhat/console.sol";

contract Transactions {
    uint256 transactionCount;

    event Transfer(address from, address receiver, uint amount, string message, uint256 timestamp, string keyword);
  
    struct TransferStruct {
        address sender;
        address receiver;
        uint amount;
        string message;
        uint256 timestamp;
        string keyword;
    }

    TransferStruct[] transactions;

    function addToBlockchain(address payable receiver, uint amount, string memory message, string memory keyword) public {
        transactionCount += 1;
        transactions.push(TransferStruct(msg.sender, receiver, amount, message, block.timestamp, keyword));

        emit Transfer(msg.sender, receiver, amount, message, block.timestamp, keyword);
    }

    function getAllTransactions() public view returns (TransferStruct[] memory) {
        return transactions;
    }

    function getTransactionCount() public view returns (uint256) {
        return transactionCount;
    }
}

0 Answers0