solidity – How One Contract Sends Ether to Another Contract with More Than 2300 Gas

contract-developmentcontract-invocationgassolidity

I want one contract to collect a certain amount of finney before sending it to another contract, but I can't simply send in with C2.send(thisMuch).

function() {
    Dividend m = Dividend(dividendAddr);
    if (this.balance >= 70 finney) {
        uint sendProfit = this.balance;
    }
    m.Enter.send(sendProfit);
}

This is what I have so far, but I'm completely lost when it comes to sending finney from one contract to the next. How can I do that?

I have made two contracts on how I think it should work.
Contract one sends it to contract two.

contract one {

    address public deployer;
    address public targetAddress;


    modifier execute {
        if (msg.sender == deployer) {
            _
        }
    }


    function one(address _targetAddress) {
        deployer = msg.sender;
        targetAddress = _targetAddress;
    }


    function forward() {
        two m = two(targetAddress);
        m.pay();
        targetAddress.send(this.balance);
    }


    function() {
        forward();
    }


    function sendBack() execute {
        deployer.send(this.balance);
    }


}

Contract two sends it back to me.

contract two {

    address public deployer;

    function two() {
        deployer = msg.sender;
    }

    function pay() {
        deployer.send(this.balance);
    }

    function() {
        pay();
    }

}

Is this how it should work?

Best Answer

In order to send Ether to another contract while specifying the amount of gas, use the call function.

targetAddress.call.gas(200000).value(this.balance)(); will call the fallback function.

targetAddress.call.gas(200000).value(this.balance)(bytes4(sha3("pay()"))); will call the pay function.

Related Topic