0

I've tried to create a smart-contract that automatically forwards incoming transaction to parent address. The issue there is gas amount since I've failed to create a function that pays for gas from the incoming transaction ether. Received ether are sent straight to parenr address, gas is paid from received ether. My code now:

  pragma solidity ^0.4.21;

   contract Forward {
       address public receiver;

// Constructor, pass the address of the account you want this contract
// to forward any incoming ether to.
function Forward(address _receiver) {
    receiver = _receiver;
}

function() public payable {
    // Forward the received ether to receiver, as well as some gas,
    // which the receiver can use to run code
    // If something goes wrong, the ether is sent back
    require(receiver.call.gas(gasleft() - 2000).value(msg.value)());
}
}
  • 1
    Gas is paid for by the account that sends the transaction. – smarx Jun 28 '18 at 23:00
  • If your code isn't doing what you want, please explain what's wrong. The sender should be able to attach as much gas as they want, and most of that should be forwarded to the receiver's anonymous function. – smarx Jun 28 '18 at 23:01

Your Answer

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

Browse other questions tagged or ask your own question.