I'm having trouble understanding getblocktemplate.

From https://en.bitcoin.it/wiki/Getblocktemplate,

I see how to build the block header and then begin hashing by incrementing the nonce, the same as I would perform work on the result of a getwork call.

What I don't understand is the following

Since you're making all the blocks yourself, you really don't ever need to get another template... until it's invalid.

After I construct my merkle root and then my block header, and hash away by incrementing the nonce, then what? How do I "create" a block? Surely I will overflow the nonce quickly with an ASIC - so what else am I varying while hashing?

I feel like I am missing a very important step.

Thanks in advance!

  • 1
    You should look at BIP 22/23
    – Nick ODell
    Commented Dec 22, 2015 at 23:34

1 Answer 1


Once a client has the template it can modify it to make the header different, giving you a new nonce range to search. In modern miners this happens thousands or tens of thousands of times a second.

  • The timestamp in the header can be updated if needed, this is known in old software as nRollTime. This method is generally not used anymore because you only get one new range per second.

  • The "extraNonce" can be updated, the random data in the coinbase transaction is altered and the merkle tree is re-hashed up to the root, which changes the header. This technique is used by Stratum miners as well.

  • Transactions can be added or removed from the tree.

GBT and Stratum are distinct from an old system called GetWork which simply gave out just a partially hashed header, every time the nonce range was exhausted the client would need to make a new request to the server they were mining from. This is what your quote is alluding to.

  • Okay, so I should be updating the nonce and extra nonce, and possibly the timestamp if I don't feel like excluding any transactions then?
    – dacox
    Commented Dec 23, 2015 at 7:15
  • 1
    You must always update the timestamp or you will produce invalid blocks. Iterate the nonce until you reach 2^32, then change the extraNonce.
    – Claris
    Commented Dec 23, 2015 at 8:35
  • The timestamp should always just be kept in sync with my current time?
    – dacox
    Commented Dec 23, 2015 at 20:48
  • That's correct.
    – Claris
    Commented Dec 24, 2015 at 0:45

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.