3

Say I have separate addresses for ethereum that are getting regular payments through different channels. How do I monitor these and immediately send balances to the main account and leave all the others empty at all times, if possible?

Also, is it possible to check pending transactions such as those here for extra speed: https://etherscan.io/txsPending

Or will it be just as fast if I wait for them to appear in the addresses? I do need it to be as quick as possible for complicated logistical reasons.

What is the best way of achieving this and what is a good gas level to speed it all up (if I don't mind losing more money for extra speed)?

As you can probably tell, I'm not an expert at all on this but would like a solution, even if it was just a simple script etc.

1 Answer 1

3

You have basically two different approaches:

  1. do the distribution via smart contract wallet or
  2. have a client watch your private-key controlled account and then initiate a payment

In detail, for 1 you could use something as simpel as this:

contract relay {
  address target;

  function relay(address _target) {
    target = _target;
  }

  function () payable {
    target.send(msg.value);
  }
}

warning: when this address receives tokens (e.g. ERC20) then those tokens will be locked up forever as it does not have functionality to forward those.

Advantages:

  • Transfer is immediate
  • Cannot fail or get forgotten

Disadvantage:

  • payer does not care about your relay and has to pay the gas for the relay transaction themselves

For option 2 you could use a little javascript snippet that runs, e.g. in the web3 console of geth (you have to unlock the accounts as well):

setInterval(function(){
  var target = web3.eth.accounts[10];
  for (var account = 0; account < 10; account++) {
    var balance = web3.eth.getBalance(web3.eth.accounts[account]);
    if(balance > 0)
      web3.eth.sendTransaction({from: web3.eth.accounts[account], to: target, value: balance});
  }
}, 10000);

warning: this requires unlocking of accounts which could lead to loss of funds if someone manages to send funds somewhere else, before your script sends it to the target address

Advantage:

  • You pay for the gas of the relay yourself, not the sender

Disadvantage:

  • Some delay of relaying the funds
  • When the machine that facilitates the payouts is switched off or goes offline, the relay stops working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.