Fetch specified block status and confidence if applicable
Query block processing status and data availability confidence using the v2/blocks endpoint.
Note
LOOKING FOR INSTRUCTIONS ON HOW TO RUN YOUR OWN LIGHT CLIENT?
You can check out our docs here for instructions on how to run your own light client.
You can check out our docs here for instructions on how to run your own light client.
- Polling the status of the block
- Querying historical block statuses
block_number- block number (required)
- status - block status
- confidence - data availability confidence, available if block processing is finished.
Status
- unavailable - block will not be processed if
latest_block - sync_depth > block_number - pending - block will be processed at some point in the future if
latest_block - sync_depth ≤ block_number ≤ latest_block - verifying-header - block processing is started, and the header finality is being checked
- verifying-confidence - block header is verified and available, confidence is being checked
- verifying-data - confidence is achieved, and data is being fetched and verified (if configured)
- finished - block header is available, confidence is achieved, and data is available (if configured)
curl "localhost:7007/v2/blocks/{insert a suitable block number}"use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
enum BlockResponse {
NotFound(String),
BlockStatus {
status: String,
confidence: Option<f64>,
},
}
const LIGHT_CLIENT_URL: &str = "https://api.lightclient.mainnet.avail.so";
#[tokio::main]
async fn main() {
let block_number = 672481; // Example block number
let block_url = format!("{LIGHT_CLIENT_URL}/v2/blocks/{block_number}");
let response = reqwest::get(&block_url).await.unwrap();
if response.status() == StatusCode::OK {
let response_text = response.text().await.unwrap();
println!("Raw response: {}", response_text);
let block_info: BlockResponse = serde_json::from_str(&response_text).unwrap();
match block_info {
BlockResponse::NotFound(message) => println!("Block status: {}", message),
BlockResponse::BlockStatus {
status,
confidence,
} => println!(
"Block status: {}, Confidence: {:?}",
status,
confidence.unwrap_or_default()
),
}
} else {
eprintln!("Failed to get block status: {}", response.status());
}
// ...error handling...
}Sample Response:
{
"status": "unavailable|pending|verifying-header|verifying-confidence|verifying-data|incomplete|finished",
"confidence": {confidence} // Optional
}
If block_number > latest_block, block status cannot yet be derived and the response on this and other endpoints with /v2/blocks/{block_number} prefix is:
Not Found