I have been experimenting with getheaders and one thing I can't seem to figure out is how to get a header for a specific hash, because getheaders doesn't provide this feature.

According to the documentation (and from my own experiments), it looks like the start position provided to the API is NOT included in the header results.

Return a headers packet containing the headers of blocks starting right after the last known hash in the block locator object, up to hash_stop or 2000 blocks

I get that this is for the purpose of synchronizing, so the semantic is "I know about this block hash, so send me all the rest I haven't seen yet, which doesn't include this hash".

But with this there's no way to figure out a block header from a block hash, I always need the previous block's hash to get the current block header. Is there no P2P API (or any trick) that lets me take a block hash and get block headers back?

1 Answer 1


The block header is part of the block, so you can request the entire thing and just consider the first 80 bytes. Software generally shouldn’t need to do this though.

  • getblocks also does the same thing, it returns the blocks AFTER the block hash I provide. This seems to be the common theme in all these APIs. All I'm trying to do is: given a block hash, get anything about the corresponding block. So far I couldn't find a way
    – Vlad
    Commented Jun 1, 2019 at 16:15
  • There’s a command that takes a hash and returns the whole block including the header.
    – Claris
    Commented Jun 1, 2019 at 16:16
  • Could you link me to this command? Would appreciate it. BTW I'm talking about the P2P API (en.bitcoin.it/wiki/Protocol_documentation), not JSON-RPC by the way. I'm asking after trying to find such method for a day.
    – Vlad
    Commented Jun 1, 2019 at 16:42
  • Use getdata: bitcoin.org/en/developer-reference#getdata
    – Ava Chow
    Commented Jun 2, 2019 at 1:40

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.