0

If I want to send ETH from contract to another user , I get error as -

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Error happened while trying to execute a function inside a smart contract

considering(fix gas limit)

What could be wrong?

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "contracts/priceConverter.sol";

contract fundMe {
    using priceConverter for uint256;

    address[] public funders;
    mapping(address => uint256) public adrresVsAmount;

    address public owner;

    constructor() {
        owner = msg.sender;
    }

    function fund() public payable {
        require(msg.value.getConversionRate() >= 1e10, "Require at least 1 ether");
        funders.push(msg.sender);
        adrresVsAmount[msg.sender] += msg.value;
    }

    function withdraw() public onlyOwner {
        require(msg.sender == owner, "Not Allowed");

        for (uint256 i = 0; i < funders.length; i++) {
            address fundersWithdraw = funders[i];
            adrresVsAmount[fundersWithdraw] = 0;
        }
        funders = new address[](0);
        
        (bool status, ) = payable(msg.sender).call{value: address(this).balance}("");
        require(status, "Failed");
    }

    function balance() public view returns (uint256) {
        return address(this).balance;
    }

    function transfer() public onlyOwner {
        address payable receiver = ***reciever*** ;
        bool success = receiver.send(address(this).balance);
        require(success, "Failed");
    }

    modifier onlyOwner {
        require(msg.sender == owner, "Not Allowed");
        _;
    }
}

4
  • Which function is throwing this error? Commented Dec 20, 2023 at 10:58
  • ``` function transfer() public onlyOwner { address payable receiver = reciever ; bool success = receiver.send(address(this).balance); require(success, "Failed"); } ``` is throwing error Commented Dec 20, 2023 at 11:07
  • You haven't defined the receiver variable anywhere in the contract. Commented Dec 20, 2023 at 11:45
  • i defined as address payable receiver = reciever_addr , where reciever_addr is address of the reciever. Commented Dec 20, 2023 at 12:06

1 Answer 1

0

It seems there is an issue with the transfer function in your fundMe contract. Specifically, the receiver variable is marked with asterisks, suggesting that it might be a placeholder that needs to be replaced with an actual address. Ensure that you have a valid Ethereum address assigned to the receiver variable before executing the transfer function. If the issue persists after replacing the placeholder, you may want to check the gas limit specified for the transaction. Gas estimation errors can occur when the gas limit is set too low for the transaction to be executed successfully. Consider increasing the gas limit in your transaction to accommodate the execution of the transfer function and ensure that it has sufficient gas to complete successfully.

Your Answer

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

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