blocks - Tezos
Example code for the /chains/main/blocks REST method. Complete guide on how to use the /chains/main/blocks REST method in GetBlock Web3 documentation
Returns a list of the most recent block hashes on the main chain, most recent first. Supports length and head query parameters to page back through history.
Endpoint
GET /chains/main/blocksQuery Parameters
length
string
Number of blocks to return
head
string
Block hash to start from
Example
export TEZOS_REST=https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/
curl "${TEZOS_REST}chains/main/blocks?length=2"const axios = require('axios');
const response = await axios.get('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/chains/main/blocks', {
params: { length: 2 },
headers: { 'Content-Type': 'application/json' }
});
console.log(response.data);import requests
response = requests.get(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/chains/main/blocks',
headers={'Content-Type': 'application/json'},
params={'length': 2}
)
print(response.json())use reqwest::Client;
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let response = client
.get("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/chains/main/blocks")
.query(&[("length", "2")])
.header("Content-Type", "application/json")
.send()
.await?
.json::<Value>()
.await?;
println!("Result: {}", response);
Ok(())
}Response
[
[
"BMblockhash0head...",
"BMblockhash1..."
]
]Response Fields
(root)
array
Array of arrays of block hashes, most recent first
Use Cases
Chain Head: Fetch the latest block hashes
History Paging: Walk backwards through recent blocks
Error Handling
400 / Bad request
Bad request
A path or body parameter was invalid
404 / Not found
Not found
The block, contract, or resource does not exist
403 / RBAC: access denied
Access denied
The GetBlock access token is missing or incorrect
Was this helpful?