getLatestLedger - Stellar

This method returns information about the latest known ledger on the Stellar network.

Parameters

  • None

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getLatestLedger",
    "id": "getblock.io"
}'

example.js

javascriptimport axios from 'axios';

const data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "getLatestLedger",
    "id": "getblock.io"
});

const config = {
    method: 'post',
    url: 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers: {
        'Content-Type': 'application/json'
    },
    data: data
};

axios(config)
    .then(response => console.log(JSON.stringify(response.data)))
    .catch(error => console.log(error));

example.py

pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"

payload = json.dumps({
    "jsonrpc": "2.0",
    "method": "getLatestLedger",
    "id": "getblock.io"
})

headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers, data=payload)
print(response.text)

example.rs

rustuse reqwest::header;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header(header::CONTENT_TYPE, "application/json")
        .body(r#"{
            "jsonrpc": "2.0",
            "method": "getLatestLedger",
            "id": "getblock.io"
        }"#)
        .send()
        .await?;
    
    println!("{}", response.text().await?);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "id": "c73c5eac58a441d4eb733c35253ae85f783e018f7be5ef974258fed067aabb36",
        "protocolVersion": 20,
        "sequence": 2539605
    }
}

Response Parameters

FieldTypeDescription
idstringHash identifier of the latest ledger
protocolVersionintegerCurrent protocol version
sequenceintegerSequence number of the latest ledger

Use Case

The getLatestLedger method is essential for:

  • Monitoring network synchronization status
  • Transaction confirmation tracking
  • Building block explorers
  • Determining current chain state
  • Sync progress verification
  • Protocol version checking

Error Handling

Status CodeError MessageCause
403ForbiddenMissing or invalid ACCESS-TOKEN
503Service UnavailableNode is not synced