0

I want to send eth to specific amount by calling smart contract.

This is my contract.

pragma solidity ^0.6.7;

contract MyContract {   
  address payable receiver;

    constructor(address _icb_address) public {
        receiver = msg.sender;
    }

    function sendEther(uint _amount) public returns(bool success) {
        receiver.transfer(_amount);
        success = true;
    }

}

I called endEther from an address which is not same as receiver, but I got this error. gas required exceeds allowance (10000000) or always failing transaction

This is failed transaction on etherscan. https://rinkeby.etherscan.io/tx/0x5652cad647ee5146cdb1e2e97f8376075a630e98021e0927cb629ed0efbe1099

It seems like transfer function is called from contract. I couldn't understand why this function is executed by contract address not msg.sender.

How to send eth to spesific address on smart contract? Could you give me any advise, please?

1

The transaction failed because your contract does not have any ETH balance and in your transaction to sendEther you also did not include any ETH.

Try either to send ETH to the contract and afterwards call sendEther or directly call sendEther with enough ETH in the transaction.

3
  • Thank you for your comment. I thought a msg.sender can send ether by calling address.transfer() if msg.sender has enough ether not contract. In my case, how to call sendEther()with ETH in the transaction?
    – gnxvw
    Sep 11 '20 at 23:38
  • I changed function name from endEther to sendEther, sorry for your inconvenience .
    – gnxvw
    Sep 11 '20 at 23:42
  • It depends on how you call the contract. If you use Metamask for example you can specify the amount of ETH in the GUI.
    – Bobface
    Sep 12 '20 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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