-
Notifications
You must be signed in to change notification settings - Fork 38
Monitoring payments and transaction handling
To monitor addresses and send payments out immediately to a main address you have basically two different approaches:
- Do the distribution via smart contract wallet or
- 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