18

Anyone can guide me on how to schedule a transaction to be sent once a specific block number is mined?

Thanks

1

4 Answers 4

15

You could run the following function :

function f( blocknumber, to_address,   value_) {


  var filter = web3.eth.filter('latest').watch(function(err, blockHash) {

  var target=blocknumber;
  if(web3.eth.blockNumber==target)
  {
      filter.stopWatching();
      //your function here
      web3.eth.sendTransaction({to:to_address, from:web3.eth.coinbase,  value: web3.toWei(value_,"ether")});

      filter = null;
      console.warn('Block reached');
      if (callback)
        return callback(false);
      else
        return false;
    }

      else {
      console.log('Waiting the block');

    }
  });
};

I've tried it in geth (while i don't use parity) and it works perfectly. be careful with the synchronous methods eth_blockNumber.

1
  • I'll switch to geth as well, I thought this was something feasible from the Parity UI that's why I asked. Thanks
    – Youssef
    Commented May 23, 2017 at 0:29
11

Just schedule it with the wallet user interface.

accounts transaction 1

Create any transaction you like, make sure you select "advanced settings" and determine the condition to be either:

  • send after block number
  • send after date and time

Parity will hold this transaction back until the condition is met. Note, for this your node needs to keep running.

2
  • Great! Will I be able to sign the transaction before scheduling it or will it prompt me to do so when the block height is reached?
    – Youssef
    Commented May 24, 2017 at 19:03
  • 2
    You will sing it immediately, but it withholds the transaction from broadcasting until the time or block condition is met.
    – q9f
    Commented May 24, 2017 at 22:12
4

If your question is about how to send a transaction yourself at any point after a certain block height is reached, then you can run an ever-running daemon on a host you control, that will do it in a programmatic way – like the answer from @BadrBelaj.

If on the other hand what you want is to send a transaction to the network now and have it executed automatically by the network once at a certain block height, then you can't do it natively at Ethereum level. However, there are neat deployed smart contracts such as the Ethereum Alarm Clock, that rely on the crowd to do the work "the Ethereum way". It's very clever and maybe it will solve your use case.

1
  • 1
    Yes, Badr's answer is exactly what I need. The second option doesn't seem optimal to me as it's not really automatic.
    – Youssef
    Commented May 23, 2017 at 4:33
0

It's quite easy to do using Ethereum Alarm Clock, which has been deployed to mainnet and since then working perfectly. 100% transactions have been executed so far.

You can schedule a transaction for specific block/time using following ways:

  1. Use MyCrypto (toggle "Send Later" button) - here's helpful tutorial.

MyCrypto interface for scheduling

  1. Use Ethereum Alarm Clock DAPP

Both ways are equally good.

About the protocol itself - it has been security audited. There was more than 1000 ETH already moved through the protocol.


Ethereum Alarm Clock is decentralized and automatic. It's currently the best way to schedule a transaction and is not subject to problems that solutions posted in other answers are.

Addressing other answers:

Someone here mentioned that EAC way is not the best, because "it's not automatic". Well, just to say - it is fully automatic. Other answer mentions using local client to schedule transaction - it's centralized way, subject to power and internet shortages, as well as to software bugs. You also need to run your computer round the clock for this work.

1
  • I can't see the mycrypto option anymore. Commented Sep 23 at 20:07

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.