> For the complete documentation index, see [llms.txt](https://docs.circular.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.circular.fi/v2/block/examples.md).

# Examples

{% tabs %}
{% tab title="Javascript" %}

```javascript
import axios from 'axios';

const API_URL = 'https://pro.circular.fi/v2/block';
const API_KEY = 'your-api-key'; // Replace with your key
const blockNumber = 411331405;

async function getBlock() {
  try {
    const res = await axios.get(`${API_URL}/${blockNumber}`, {
      headers: {
        'Content-Type': 'application/json',
        'x-api-key': API_KEY
      }
    });

    console.log('Block:', res.data);
  } catch (e) {
    console.error('Error:', e?.response?.data || e.message);
  }
}

getBlock();
```

{% endtab %}

{% tab title="Typescript" %}

```typescript
import axios, { AxiosResponse } from 'axios';

const API_URL = 'https://pro.circular.fi/v2/block';
const API_KEY = 'your-api-key'; // Replace with your key

type BlockResponse = unknown;

export async function getBlock(
  blockNumber: number
): Promise<BlockResponse> {
  try {
    const res: AxiosResponse<BlockResponse> = await axios.get(
      `${API_URL}/${blockNumber}`,
      {
        headers: {
          'Content-Type': 'application/json',
          'x-api-key': API_KEY
        }
      }
    );

    console.log('Block:', res.data);
    return res.data;
  } catch (e: any) {
    throw new Error(e?.response?.data || e.message);
  }
}

getBlock(411331405);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from typing import Dict, Any

API_URL = "https://pro.circular.fi/v2/block"
API_KEY = "your-api-key"  # Replace with your key


def get_block(block_number: int) -> Dict[str, Any]:
    """
    Fetch a Solana block with typed and enriched transactions.

    :param block_number: Solana block number
    :return: API response as a dictionary
    """
    headers = {
        "Content-Type": "application/json",
        "x-api-key": API_KEY
    }

    try:
        response = requests.get(
            f"{API_URL}/{block_number}",
            headers=headers,
            timeout=30
        )
        response.raise_for_status()
        return response.json()

    except requests.exceptions.RequestException as e:
        raise RuntimeError(
            f"Block request failed: "
            f"{getattr(e.response, 'text', str(e))}"
        )


if __name__ == "__main__":
    result = get_block(411331405)
    print("Block:", result)
```

{% endtab %}

{% tab title="Rust" %}

```rust
use reqwest::Client;
use serde_json::Value;
use std::error::Error;

const API_URL: &str = "https://pro.circular.fi/v2/block";
const API_KEY: &str = "your-api-key"; // Replace with your key

pub async fn get_block(
    block_number: u64,
) -> Result<Value, Box<dyn Error>> {
    let client = Client::new();

    let response = client
        .get(format!("{}/{}", API_URL, block_number))
        .header("Content-Type", "application/json")
        .header("x-api-key", API_KEY)
        .send()
        .await?
        .error_for_status()?
        .json::<Value>()
        .await?;

    Ok(response)
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let result = get_block(411331405).await?;
    println!("Block: {}", result);

    Ok(())
}
```

{% endtab %}
{% endtabs %}
