# getblock

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://bitcoin-mainnet.g.alchemy.com/v2/{apiKey}

Returns information about a block, based on the provided block hash.


Reference: https://www.alchemy.com/docs/chains/bitcoin/bitcoin-api-endpoints/getblock

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| blockhash | string | Yes | The hash of the block to retrieve. |
| verbosity | enum | No | Level of detail to return.  - 0: hex-encoded string, - 1: basic block info, - 2: with transactions, - 3: with transactions + input prevouts.  |

## Result

**result** (object): The block object or hex string, depending on verbosity.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getblock",
  "params": [
    "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80",
    2
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "hash": "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80",
    "confirmations": 151,
    "height": 894470,
    "version": 537067520,
    "versionHex": "20030000",
    "merkleroot": "9d93ae25de98e5ed33aec9ccfea612c3b5b181a60171ba564ec1634786b04bc6",
    "time": 1745931642,
    "mediantime": 1745928076,
    "nonce": 766301978,
    "bits": "170248b6",
    "target": "0000000000000000000248b60000000000000000000000000000000000000000",
    "difficulty": 123234387977050.9,
    "chainwork": "0000000000000000000000000000000000000000bf64054821a76841a63cb26e",
    "nTx": 2186,
    "previousblockhash": "00000000000000000001aa9a63c6c0774a767f7a4d37d2bce3658728de76a146",
    "nextblockhash": "00000000000000000000cb8a1d7945b960985579525957bcc37b22174f1ecb31",
    "strippedsize": 844254,
    "size": 1460798,
    "weight": 3993560,
    "tx": [
      "c86b4846175942038cc9da086e506aa8a441beada92f1678fb1fe35d640366db"
    ]
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getblock",
  "params": [
    "00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80",
    2
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getblock',
    params: ['00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80', 2]
  })
};

fetch('https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getblock",
    "params": ["00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80", 2]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getblock\",\n  \"params\": [\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\",\n    2\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getblock\",\n  \"params\": [\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\",\n    2\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getblock\",\n  \"params\": [\n    \"00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80\",\n    2\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: getblock
summary: Get block details by block hash
description: |
  Returns information about a block, based on the provided block hash.
params:
  - name: blockhash
    required: true
    description: The hash of the block to retrieve.
    schema:
      title: Bitcoin Block Hash
      type: string
      pattern: ^[a-fA-F0-9]{64}$
      description: A 64-character hex string representing the block hash.
  - name: verbosity
    required: false
    description: |
      Level of detail to return.  - 0: hex-encoded string, - 1: basic block info, - 2: with transactions, - 3: with transactions + input prevouts.
    schema:
      type: integer
      default: 1
      enum:
        - 0
        - 1
        - 2
        - 3
result:
  name: result
  description: The block object or hex string, depending on verbosity.
  schema:
    title: Bitcoin Block
    type: object
    required:
      - hash
      - confirmations
      - height
      - version
      - merkleroot
      - time
      - tx
    properties:
      hash:
        type: string
        description: The block hash.
      confirmations:
        type: integer
        description: Number of confirmations or -1 if block not on main chain.
      size:
        type: integer
        description: Block size in bytes.
      strippedsize:
        type: integer
        description: Block size excluding witness data.
      weight:
        type: integer
        description: Block weight as defined in BIP 141.
      height:
        type: integer
        description: Block height or index.
      version:
        type: integer
        description: Block version.
      versionHex:
        type: string
        description: Block version in hex.
      merkleroot:
        type: string
        description: Merkle root.
      time:
        type: integer
        description: Block time in UNIX timestamp.
      mediantime:
        type: integer
        description: Median block time.
      nonce:
        type: integer
        description: Nonce used for mining.
      bits:
        type: string
        description: nBits field of block header.
      target:
        type: string
        description: The target threshold for the block’s hash (derived from `bits`).
      difficulty:
        type: number
        format: double
        description: Difficulty at the time of mining.
      chainwork:
        type: string
        description: Expected number of hashes to produce the chain.
      nTx:
        type: integer
        description: Number of transactions in the block.
      previousblockhash:
        type: string
        description: Hash of the previous block.
      nextblockhash:
        type: string
        description: Hash of the next block.
      tx:
        type: array
        description: List of transaction IDs included in the block.
        items:
          type: string
          description: Transaction ID
examples:
  - name: getblock example
    params:
      - name: blockhash
        value: 00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80
      - name: verbosity
        value: 2
    result:
      name: result
      value:
        hash: 00000000000000000000669ed57030eb18020ee7029c064f10505156be203d80
        confirmations: 151
        height: 894470
        version: 537067520
        versionHex: '20030000'
        merkleroot: 9d93ae25de98e5ed33aec9ccfea612c3b5b181a60171ba564ec1634786b04bc6
        time: 1745931642
        mediantime: 1745928076
        nonce: 766301978
        bits: 170248b6
        target: 0000000000000000000248b60000000000000000000000000000000000000000
        difficulty: 123234387977050.9
        chainwork: 0000000000000000000000000000000000000000bf64054821a76841a63cb26e
        nTx: 2186
        previousblockhash: 00000000000000000001aa9a63c6c0774a767f7a4d37d2bce3658728de76a146
        nextblockhash: 00000000000000000000cb8a1d7945b960985579525957bcc37b22174f1ecb31
        strippedsize: 844254
        size: 1460798
        weight: 3993560
        tx:
          - c86b4846175942038cc9da086e506aa8a441beada92f1678fb1fe35d640366db
```
