1

I would like to know if it was possible to automatically send any ETH amout to an address "B" just after receiving them on an address "A"? Maybe via a script? I need help

0

You're in luck! Ethereum's smart contracts can do just the thing!

Check out this code:

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)());
    }
}

This smart contract will send any received ether to receiver.

Now, to use this contract, you will have to deploy it. To do that, take a look at the Solidity documentation.

Also: please only use this contract on the testnet, unless you are sure you know what you are doing. It's real money we're dealing with here.

If you want to create smart contracts for yourself, you can use Remix IDE to write and test them!

| improve this answer | |
  • thank you very much for this quick answer, I will indeed try on the testnet. – J. DOE Apr 12 '18 at 19:05
0

I tried the contract forwarder, but this is not working.

Send ETH to the ETH address, it just sends the ETH. No forwarding. Send ETH to the contract address, out of gas.

Do we need to put in an address somewhere in the solidity code?

| improve this answer | |

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.