Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Monitoring payments and transaction handling

Platonx99 edited this page Jun 5, 2018 · 8 revisions

To monitor addresses and send payments out immediately to a main address 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 simple 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 webchaind (you have to unlock the accounts as well):

setInterval(function(){ var target = web3.webchain.accounts[10]; for (var account = 0; account < 10; account++) { var balance = web3.webchain.getBalance(web3.webchain.accounts[account]); if(balance > 0) web3.webchain.sendTransaction({from: web3.webchain.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