This is probably a simple problem to fix, but it is very frustrating.
I am developing in Solidity using Remix 0.5.10.
I have a loan contract that collects funds from borrowers. I now want to collect those funds and pass them through to the portfolio which owns those loans. The code is as follows:
function passThrough() payable public
{
address(portfolio).transfer(address(this).balance);
}
The error I get is:
**Gas Estimation Fail**
Gas estimation errored with the following message (see below).
The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error.
If I do press Send Anyway, I get the following error:
I would have thought that gas will just be taken from the amount sent correct? Or do I need to reduce the amount snet by the estimated amount of gas explicitly?
@Ismael: Regarding your question, yes Portfolio is a contract and it has a fallback function which is as follows:
function () payable external {
// fallback function to receive funds
received = msg.value;
availableFunds += received;
} // function () payable external {
After trying Ismael's suggestion, I have changed the call as follows:
address(portfolio).call.gas(100000).value(address(this).balance);
I also tried:
address(portfolio).call.value(address(this).balance).gas(100000)("");
Neither worked. They do not throw up an error, however, for some reason the funds are not transferred. Now I am really confused. I understand the point about not enough gas, but with that solved and the transaction completing succesfully, why is the value not also sent? I did check to make sure that there was a balance to send, by the way!
I really appreciate your feedback. Thanks.