[Ethereum] Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending

solidity

I wrote one contract to call a function from another contract like below

pragma solidity ^0.5.1;

contract test3 {       
    address watch_addr = address(0x1234567963); //deployed contract address

    function balanceOf(address owner) public {
        watch_addr.call(abi.encodeWithSignature("balanceOf(address)", owner));
        return balanceOf(owner);
    }
}

I want to call a balanceOf function in deployed contract.Now I deployed the new contract successfully but I am getting the following error while calling the balanceOf function

error:"Gas estimation errored with the following message (see below).
The transaction execution will likely fail. Do you want to force
sending? "

Can any one please tell me the solution? –Thanks

Best Answer

You are calling balanceOf inside balanceOf , so it will be executed infinitely. Real estimation of gas for such actions are not possible or infinite. That's why you are getting this error. With smart contract, be damn sure with your logic.

Related Topic