Anyone can guide me on how to schedule a transaction to be sent once a specific block number is mined?
Thanks
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
.
Just schedule it with the wallet user interface.
Create any transaction you like, make sure you select "advanced settings" and determine the condition to be either:
Parity will hold this transaction back until the condition is met. Note, for this your node needs to keep running.
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.
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:
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.