0

I have some trouble creating two interacting contracts. The first contract should receive ether from a user at a function payRate() and forward the amount to another contract, which is saved at the address pool. Both functions (the payRate() and the receivePayment() function) are payable and receivePayment() is working if called from a user. Mining the contracts works fine but using the functions fails. I also tried a different versions with small fixed amounts of ether, same result.

The environment I used is Visual Studio Code with the Solidity extension as compiler and Parity (dev. chain).

    pragma solidity ^0.4.18;

    contract sendEther {

    address owner;
    address pool;
    uint amountPaid;

    function sendEther(address _pool) public {
    pool = _pool;
    owner = msg.sender;
    }

    function payRate() payable {
       require(pool != address(0));

       pool.transfer(msg.value);
       amountPaid += msg.value;

       //other ways of sending i tried:
       //TransactionPool test = TransactionPool(pool);
       //test.receivePayment().value(msg.value);

       //pool.call.value(msg.value)(bytes4(keccak256("receivePayment()")));
    }
    }

and

    pragma solidity ^0.4.18;

    contract TransactionPool {

    address owner;
    uint totalPayments;

    function TransactionPool() public {
       owner = msg.sender;
    }

    function receivePayment() public payable {
       totalPayments += msg.value;
    }

    function() payable public { //fallback function
       totalPayments += msg.value;
    }
    }

Thanks!

  • What error message are you getting? – Malone Nov 9 '17 at 16:24
0

Check syntax to make an external call in solidity docs

function payRate() payable {
   require(pool != address(0));

   amountPaid += msg.value;

   TransactionPool(pool).receivePayment.value(msg.value)();
}

The fail is at pool.transfer(msg.value); this invokes the pool's fallback function with only 2300 of gas stipend, and pool's fallback tries to modify totalPayments and run out of gas.

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.