0

I am trying to find a way how to automatically transfer funds from one address to another after new block is sealed.

Scenario would look like this:

1. New block sealed 
2. Check source account balance 
3. Deduct tx cost from balance 
4. Unlock source account
5. Send available balance (minus tx cost) from source to destination 
6. Wait for new block to be sealed. 

I have simplified version but it does not seem to get executed.

function transferFunds(){
  var source = 0x123456789.....
  var source_pass = "secretpassword"
  var dest = 0x567890...
  var txcost = eth.estimateGas({from: source, to: dest, value: web3.toWei(200, 'gwei')}); 

  var fundsAvailable = eth.getBalance(source) - txcost; 

  if( fundsAvailable > 0){

    personal.unlockAccount(source, source_password, "60");
    eth.sendTransaction({from: source, to: dest, value: web3.toHex(fundsAvailable)}); 

    console.log("Transferred " + web3.fromWei(fundsAvailable) + " ETH");

  }
  else{

    console.log("Insufficient funds");
  }

}


transferFunds();

Here are my questions:

1. What filter should I use as "pending" block is not suitable I think 
2. What am I missing in the above example so it does not execute transaction ?
3. Any other comments on how to make it better are welcome

Thanks

5

0

Your Answer

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