[Ethereum] Ensuring a transaction is included in a specific block

block-intervalconfirmationsgasmyetherwalletparity

I have been sending myself transactions back and forward between MEW and Parity trying to get a transaction included in a specific block number however I seem to be always 3 – 6 blocks behind where I want it.

This is in preparation for the Golem crowdsale, I want to make sure I don't miss out and ideally my transaction lands in the first block from when the sale starts.

A few questions:

  • Is it a sound strategy to broadcast the transaction 1, 2, or 3 blocks before the start block (on my 6 test transactions this still put me a few blocks after the 'start block'), what about the risk of my transaction being confirmed before the sale start block?
  • What are the best gas setting to get my transaction confirmed as fast as possible, if I include 2,000,000 gas how much is that in Eth and do I need to alter the gas price to give myself the best chance of it getting confirmed quickly?

Thanks for having a read, would be interested to hear what others would do in this situation to give the best chance of getting my Eth into the Golem crowdsale.

I have recorded my tests, what block I was hoping for and what block the transaction confirmed and the gas setting I used if that info is handy I could post it.

Thanks in advance!

Best Answer

It's basically impossible to guarantee a transaction occurs in a given block. There's too many factors--network latency, the block gas limit, uncles, miners who mine empty blocks, other transactions, etc. Chances are, by the time you're actually looking at block X, it's too late to get in block X+1, since a miner may have already decided what transactions to mine.

Technically, you could write a contract that only relays a transaction if the block number is right. This is unlikely to help you, as it will increase gas use in that transaction and therefore make it more difficult to actually get in that specific block.

It's also unlikely that you can get the first block after a crowdsale in general, because the specific block of the sale contract being created is also unknown. It's quite possible that, as a large contract, it won't fit and it will be delayed until the blocks aren't so full. The existence of the crowdsale contract could be checked by another contract, but again, this might not actually help you.

OK, but what do you actually do?

A higher gas won't help. It's how many steps, at most, the transaction will pay for. A higher gas price will give your transaction priority over others. The cost for a transaction is (gasUsed * gasPrice) wei, and one ETH is 10^18 wei. Note that no matter how much gas is specified, you only pay for how much you use.

Timing-wise, I'd just wait until the contract is ready, then send the transaction. There's not much use in trying to get it exact as soon as possible, since you probably can't.

Related Topic