<p>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. </p>

CC BY-SA 4.0
2019-06-01T16:15:33.783Z
`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
CC BY-SA 4.0
2019-06-01T16:16:20.513Z
There’s a command that takes a hash and returns the whole block including the header.
Claris
CC BY-SA 4.0
2019-06-01T16:42:09.607Z
Could you link me to this command? Would appreciate it. BTW I'm talking about the P2P API (https://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
CC BY-SA 4.0
2019-06-02T01:40:00.883Z
Use `getdata`: https://bitcoin.org/en/developer-reference#getdata
Ava Chow
CC BY-SA 4.0
2019-06-01T15:08:38.700Z
2019-06-01T15:08:38.700Z
Claris
<p>I have been experimenting with <code>getheaders</code> and one thing I can't seem to figure out is how to get a header for a specific hash, because <code>getheaders</code> doesn't provide this feature.</p>

<p>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. </p>

<blockquote>
  <p>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</p>
</blockquote>

<p>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". </p>

<p>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?</p>

<bitcoin-core><bitcoind><protocol>
How to get block headers from block hash using P2P API?
Vlad
# How to get block headers from block hash using P2P API?

(Asked by: username_0 on 2019-06-01)

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?

**Tags:** bitcoin-core, bitcoind, protocol


---

## 1 answers

### Answer by username_1 on 2019-06-01. Score: 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.

> **Comments:**
> **username_0**: `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  
> **username_1**: There’s a command that takes a hash and returns the whole block including the header.  
> **username_0**: Could you link me to this command? Would appreciate it. BTW I'm talking about the P2P API (https://en.bitcoin.it/wiki/Protocol_documentation), not JSON-RPC by the way. I'm asking after trying to find such method for a day.  
> **username_2**: Use `getdata`: https://bitcoin.org/en/developer-reference#getdata  

---

