chain_getBlockHash - JSON-RPC Method
Description#
Returns the block hash for a given block number on Enjin Matrix. When called without parameters it returns the hash of the latest block. Hashes are required for deterministic storage reads and verifying block inclusion proofs.
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
blockNumber | number | No | Block height as a decimal integer. If omitted, returns the best block hash |
Returns#
| Field | Type | Description |
|---|---|---|
result | string | Hex-encoded block hash |
Request Examples#
{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [],
"id": 1
}
{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [6781838],
"id": 42
}
Response Example#
{
"jsonrpc": "2.0",
"result": "0x1873093eade39aa409f64537dd972c27156e4691fc0fda227a06d50c52ad5fef",
"id": 42
}
Code Examples#
- cURL
- Python
- JavaScript
# Latest block hash
curl https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [],
"id": 1
}'
# Hash for block 6,781,838
curl https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [6781838],
"id": 42
}'
import json
import requests
def block_hash(height=None):
payload = {
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [] if height is None else [height],
"id": 1,
}
return requests.post(
"https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY",
headers={"Content-Type": "application/json"},
data=json.dumps(payload),
timeout=10,
).json()["result"]
print(block_hash(6781838))
async function getBlockHash(height) {
const response = await fetch('https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'chain_getBlockHash',
params: typeof height === 'number' ? [height] : [],
id: 1
})
});
return (await response.json()).result;
}
Notes#
- Provide the returned hash to
chain_getBlockorstate_getStoragefor deterministic reads. - Supply decimal heights when querying by number; JSON-RPC clients perform conversion to hex automatically.
- For archival queries across Matrix and the Enjin Relaychain, track hashes per network—they are distinct consensus layers.