# chain_getBlock - FLOP RPC Method

Retrieves complete block information from FLOP, including the block header, extrinsics, and justifications.

> **Why FLOP?** Build on the Substrate Proof of Inference Layer 1 built for autonomous AI agents with Proof of Inference with TOPLOC activation commitments, full historical archive state from genesis, and JSON-RPC v2 archive and chainHead APIs.

## Use Cases

The `chain_getBlock` method is essential for:

- **Block explorers** - Display complete block information
- **Chain analysis** - Analyze block production patterns
- **Transaction verification** - Confirm extrinsic inclusion for Proof of Inference settlement, 1-second BABE blocks with AlephBFT finality, archive state queries, and HTLC atomic swaps
- **Data indexing** - Build historical blockchain databases

## Best Practices

- Cache block data by hash -- blocks are immutable once finalized on Substrate chains
- Use `chain_getBlockHash` first to resolve block number to hash before calling this method
- Handle `null` results gracefully for non-existent blocks
- Combine with `chain_getFinalizedHead` for consensus-safe block retrieval

## Request Parameters

- `blockHash` (`String, optional`): Hex-encoded block hash. If omitted, returns latest block

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "chain_getBlock",
  "params": ["0x33cb4ba72b743fe7d82e581aeac97dd7108b5dfbf87c84a624e943379a33a96e"],
  "id": 1
}
```

## Response Fields

- `block` (`Object, required`): Complete block data
- `block.header` (`Object, required`): Block header information
- `block.header.parentHash` (`String, required`): Hash of the parent block
- `block.header.number` (`String, required`): Block number (hex-encoded)
- `block.header.stateRoot` (`String, required`): Root of the state trie
- `block.header.extrinsicsRoot` (`String, required`): Root of the extrinsics trie
- `block.extrinsics` (`Array, required`): Array of extrinsics in the block
- `justifications` (`Array, required`): Block justifications (if available)

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "block": {},
    "block.header": {},
    "block.header.parentHash": "<value>",
    "block.header.number": "<value>",
    "block.header.stateRoot": "<value>",
    "block.header.extrinsicsRoot": "<value>",
    "block.extrinsics": [],
    "justifications": []
  }
}
```

## Code Examples

cURL
JavaScript
Python

```bash
# Get latest block
curl https://api-flop-testnet.n.dwellir.com/YOUR_API_KEY \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "chain_getBlock",
    "params": [],
    "id": 1
  }'

# Get specific block
curl https://api-flop-testnet.n.dwellir.com/YOUR_API_KEY \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "chain_getBlock",
    "params": ["0x33cb4ba72b743fe7d82e581aeac97dd7108b5dfbf87c84a624e943379a33a96e"],
    "id": 1
  }'
```

```javascript
import { ApiPromise, WsProvider } from '@polkadot/api';

const provider = new WsProvider('wss://api-flop-testnet.n.dwellir.com/YOUR_API_KEY');
const api = await ApiPromise.create({ provider });

// Get latest block
const latestHash = await api.rpc.chain.getBlockHash();
const latestBlock = await api.rpc.chain.getBlock(latestHash);

console.log('Latest block:', {
  number: latestBlock.block.header.number.toNumber(),
  hash: latestHash.toHex(),
  extrinsicsCount: latestBlock.block.extrinsics.length
});

// Get specific block
const blockHash = '0x33cb4ba72b743fe7d82e581aeac97dd7108b5dfbf87c84a624e943379a33a96e';
const block = await api.rpc.chain.getBlock(blockHash);
console.log('Block extrinsics:', block.block.extrinsics.length);

await api.disconnect();
```

```python
import requests
import json

def get_block(block_hash=None):
    url = 'https://api-flop-testnet.n.dwellir.com/YOUR_API_KEY'
    params = [block_hash] if block_hash else []

    payload = {
        'jsonrpc': '2.0',
        'method': 'chain_getBlock',
        'params': params,
        'id': 1
    }

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

    if 'error' in data:
        raise Exception(f"RPC Error: {data['error']}")

    return data['result']

# Get latest block
latest_block = get_block()
block_number = int(latest_block['block']['header']['number'], 16)
print(f'Latest block number: {block_number}')

# Get specific block
specific_block = get_block('0x33cb4ba72b743fe7d82e581aeac97dd7108b5dfbf87c84a624e943379a33a96e')
print(f"Extrinsics count: {len(specific_block['block']['extrinsics'])}")
```

## Related Methods

- [`chain_getBlockHash`](https://www.dwellir.com/docs/flop/chain_getBlockHash) - Get block hash by number
- [`chain_getHeader`](https://www.dwellir.com/docs/flop/chain_getHeader) - Get block header only
- [`chain_getFinalizedHead`](https://www.dwellir.com/docs/flop/chain_getFinalizedHead) - Get finalized block hash
