0

I have an issue to transfer the ether from a contract to another contract. Here is the concept code.

If the address _to is a user address. The function can transfer the ether to the user.

If the address _to is a contract address. The program will stop working.

Need help. Thanks.

pragma solidity ^0.4.19;

contract ethTransferTest {
    function ethTrans(address _to) payable public {
        uint256 pay = msg.value;
        _to.transfer(pay);
    }
}
  • Share the stack trace and contract code where funds are being sent – blockwala Jul 5 '18 at 10:29
  • could you show the code of the contract that is receiving the ether? – Jaime Jul 5 '18 at 11:36
0

This usually happens because there is a limitation in the amount of gas that the method transfer pass to the receiving contract. Transfer pass only 2300 gas which means that is the code in the fallback function of the receiving contract consumes more than 2300 gas, then the transfer will fail.

Assume these two contracts

contract ethTransferTest {
    function ethTrans(address _to) public {
        uint256 pay = msg.value;
        _to.transfer(pay);
    }
}


contract ethReceiverTest {
    function () payable public {
    }
}

This will work, but as soon as you start including methods in the fallback function in ethReceiverTest, you will start having problems. 2300 gas will only be enough for a few operations.

  • Yes. I tested the code and it is working. Thanks a lot. – deepline Jul 5 '18 at 12:30

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.