# getBlock

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

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

Returns identity and transaction information about a confirmed block in the ledger.

Reference: https://www.alchemy.com/docs/chains/solana/solana-api-endpoints/get-block

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| slot | integer | Yes | Slot number as a u64 integer. |
| Configuration | object | No | Optional configuration object containing additional settings. |

## Result

**Block information** (object): Returns block information or null if the block is not confirmed.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getBlock",
  "params": [
    237158054,
    {
      "encoding": "json",
      "transactionDetails": "none"
    }
  ],
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://solana-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlock",
  "params": [
    237158054,
    {
      "encoding": "json",
      "transactionDetails": "none"
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getBlock',
    params: [237158054, {encoding: 'json', transactionDetails: 'none'}]
  })
};

fetch('https://solana-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://solana-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getBlock",
    "params": [
        237158054,
        {
            "encoding": "json",
            "transactionDetails": "none"
        }
    ]
}
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://solana-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getBlock\",\n  \"params\": [\n    237158054,\n    {\n      \"encoding\": \"json\",\n      \"transactionDetails\": \"none\"\n    }\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://solana-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    237158054,\n    {\n      \"encoding\": \"json\",\n      \"transactionDetails\": \"none\"\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://solana-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    237158054,\n    {\n      \"encoding\": \"json\",\n      \"transactionDetails\": \"none\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getBlock
description: Returns identity and transaction information about a confirmed block in the ledger.
params:
  - name: slot
    required: true
    description: Slot number as a u64 integer.
    schema:
      type: integer
  - name: Configuration
    required: false
    description: Optional configuration object containing additional settings.
    schema:
      title: GetBlock Configuration
      type: object
      properties:
        commitment:
          title: Commitment Level
          type: string
          description: Configures the state commitment for querying.
          enum:
            - processed
            - confirmed
            - finalized
          default: finalized
        encoding:
          type: string
          description: Encoding format for transactions.
          enum:
            - json
            - jsonParsed
            - base58
            - base64
          default: json
        transactionDetails:
          type: string
          description: Level of transaction detail to return.
          enum:
            - full
            - accounts
            - signatures
            - none
          default: full
        maxSupportedTransactionVersion:
          type: integer
          description: Max transaction version to return.
        rewards:
          type: boolean
          description: Include rewards array if true.
          default: true
examples:
  - name: getBlock example
    params:
      - name: slot
        value: 237158054
      - name: Configuration
        value:
          encoding: json
          transactionDetails: none
result:
  name: Block information
  description: Returns block information or null if the block is not confirmed.
  schema:
    title: Block Information
    type: object
    properties:
      blockhash:
        type: string
        description: Blockhash of this block.
      previousBlockhash:
        type: string
        description: Blockhash of the parent block.
      parentSlot:
        type: integer
        description: Slot index of the parent block.
      transactions:
        type: array
        description: Array of transaction objects.
        items:
          title: Transaction
          type: object
          properties:
            slot:
              type: integer
              description: The slot this transaction was processed in.
            transaction:
              type: object
              description: The transaction details, either in JSON format or encoded binary data, depending on the encoding parameter.
              properties:
                signatures:
                  type: array
                  description: An array of signatures applied to the transaction.
                  items:
                    type: string
                message:
                  type: object
                  properties:
                    accountKeys:
                      type: array
                      description: An array of account keys used by the transaction.
                      items:
                        title: Pubkey
                        type: string
                        description: Base-58 encoded public key.
                    header:
                      type: object
                      properties:
                        numRequiredSignatures:
                          type: integer
                          description: The number of signatures required for the transaction.
                        numReadonlySignedAccounts:
                          type: integer
                          description: Number of read-only signed accounts.
                        numReadonlyUnsignedAccounts:
                          type: integer
                          description: Number of read-only unsigned accounts.
                    instructions:
                      type: array
                      items:
                        type: object
                        properties:
                          accounts:
                            type: array
                            description: List of account indices to be passed to the program.
                            items:
                              type: integer
                          data:
                            type: string
                            description: The program input data encoded as a base-58 string.
                          programIdIndex:
                            type: integer
                            description: Index into the message.accountKeys array indicating the program account.
                    recentBlockhash:
                      type: string
                      description: The recent blockhash used by the transaction.
            blockTime:
              type: integer
              nullable: true
              description: Estimated production time as a Unix timestamp. Null if not available.
            meta:
              type: object
              nullable: true
              description: Transaction status metadata.
              properties:
                err:
                  type: object
                  nullable: true
                  description: Error if the transaction failed, null if it succeeded.
                fee:
                  type: integer
                  description: Fee charged for this transaction.
                preBalances:
                  type: array
                  description: Array of u64 account balances before the transaction.
                  items:
                    type: integer
                postBalances:
                  type: array
                  description: Array of u64 account balances after the transaction.
                  items:
                    type: integer
                innerInstructions:
                  type: array
                  nullable: true
                  description: List of inner instructions or null if not enabled.
                  items:
                    title: Inner Instruction
                    type: object
                    properties:
                      index:
                        type: integer
                        description: Index of the instruction in the transaction.
                      instructions:
                        type: array
                        items:
                          type: object
                          properties:
                            programId:
                              title: Pubkey
                              type: string
                              description: Program ID invoked by this instruction.
                            accounts:
                              type: array
                              description: Account addresses involved in this instruction.
                              items:
                                title: Pubkey
                                type: string
                                description: Base-58 encoded public key.
                            data:
                              type: string
                              description: The program input data encoded as a base-58 string.
                preTokenBalances:
                  type: array
                  nullable: true
                  description: Token balances before the transaction, if available.
                  items:
                    title: Token Balance
                    type: object
                    properties:
                      amount:
                        type: string
                        description: The raw balance without decimals, a string representation of u64.
                      decimals:
                        type: integer
                        description: Number of base-10 digits to the right of the decimal place.
                      uiAmount:
                        type: number
                        nullable: true
                        description: The balance, using mint-prescribed decimals. **DEPRECATED**
                      uiAmountString:
                        type: string
                        description: The balance as a string, using mint-prescribed decimals.
                postTokenBalances:
                  type: array
                  nullable: true
                  description: Token balances after the transaction, if available.
                  items:
                    title: Token Balance
                    type: object
                    properties:
                      amount:
                        type: string
                        description: The raw balance without decimals, a string representation of u64.
                      decimals:
                        type: integer
                        description: Number of base-10 digits to the right of the decimal place.
                      uiAmount:
                        type: number
                        nullable: true
                        description: The balance, using mint-prescribed decimals. **DEPRECATED**
                      uiAmountString:
                        type: string
                        description: The balance as a string, using mint-prescribed decimals.
                logMessages:
                  type: array
                  nullable: true
                  description: Array of string log messages or null if not enabled.
                  items:
                    type: string
                rewards:
                  type: array
                  nullable: true
                  description: Transaction-level rewards.
                  items:
                    title: Reward
                    type: object
                    properties:
                      pubkey:
                        title: Pubkey
                        type: string
                        description: The public key of the rewarded account.
                      lamports:
                        type: integer
                        description: The amount of reward in lamports.
                      postBalance:
                        type: integer
                        description: The balance of the account after the reward was applied.
                      rewardType:
                        type: string
                        description: The type of reward.
                        enum:
                          - fee
                          - rent
                          - voting
                          - staking
                      commission:
                        type: integer
                        nullable: true
                        description: The vote account commission when the reward was credited, if applicable.
                loadedAddresses:
                  type: object
                  nullable: true
                  description: Transaction addresses loaded from address lookup tables.
                returnData:
                  type: object
                  nullable: true
                  description: Return data generated by an instruction in the transaction.
                computeUnitsConsumed:
                  type: integer
                  nullable: true
                  description: Number of compute units consumed by the transaction.
            version:
              type: string
              nullable: true
              description: Transaction version. Undefined if not set.
      signatures:
        type: array
        description: Array of transaction signatures.
        items:
          type: string
      rewards:
        type: array
        description: Block-level rewards.
        items:
          title: Reward
          type: object
          properties:
            pubkey:
              title: Pubkey
              type: string
              description: The public key of the rewarded account.
            lamports:
              type: integer
              description: The amount of reward in lamports.
            postBalance:
              type: integer
              description: The balance of the account after the reward was applied.
            rewardType:
              type: string
              description: The type of reward.
              enum:
                - fee
                - rent
                - voting
                - staking
            commission:
              type: integer
              nullable: true
              description: The vote account commission when the reward was credited, if applicable.
      blockTime:
        type: integer
        description: Estimated production time as Unix timestamp.
      blockHeight:
        type: integer
        description: Number of blocks beneath this block.
```
