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β
# 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
}'
JavaScriptβ
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;
}
Pythonβ
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))
Notesβ
- Provide the returned hash to
chain_getBlock
orstate_getStorage
for 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.