getblock - Litecoin

This method returns an object with information about the block for the given hash.

Parameters

ParameterTypeDescription
blockhashstring (hex)The hash of the block to get, encoded as hex in RPC byte order.
verbositynumber (int)Optional. Set to one of the following verbosity levels: 0 - Get the block in serialized block format; 1 - Get the decoded block as a JSON object (default); 2 - Get the decoded block as a JSON object with transaction details.

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": "getblock",
    "params": ["a1b2c3d4e5f6...blockhash...", 1],
    "id": "getblock.io"
}'

axios.js

javascriptimport axios from 'axios';

const data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "getblock",
    "params": ["a1b2c3d4e5f6...blockhash...", 1],
    "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));

request.py

pythonimport requests
import json

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

payload = json.dumps({
    "jsonrpc": "2.0",
    "method": "getblock",
    "params": ["a1b2c3d4e5f6...blockhash...", 1],
    "id": "getblock.io"
})

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

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

main.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": "getblock",
            "params": ["a1b2c3d4e5f6...blockhash...", 1],
            "id": "getblock.io"
        }"#)
        .send()
        .await?;
    
    println!("{}", response.text().await?);
    Ok(())
}

Response

response.json

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "hash": "a1b2c3d4e5f6...blockhash...",
        "confirmations": 100,
        "strippedsize": 228,
        "size": 264,
        "weight": 948,
        "height": 2750000,
        "version": 536870912,
        "versionHex": "20000000",
        "merkleroot": "4a5b6c7d8e9f...",
        "tx": ["txid1", "txid2"],
        "time": 1640000000,
        "mediantime": 1639999000,
        "nonce": 123456789,
        "bits": "1a0fffff",
        "difficulty": 12345678.90,
        "chainwork": "0000000000000000000000000000000000000000000000000000000000000001",
        "nTx": 2,
        "previousblockhash": "0000000000000000000000000000000000000000000000000000000000000000",
        "nextblockhash": "1111111111111111111111111111111111111111111111111111111111111111"
    }
}

Response Parameters

FieldTypeDescription
hashstringThe block hash (same as provided).
confirmationsnumberThe number of confirmations, or -1 if not in main chain.
sizenumberThe block size in bytes.
heightnumberThe block height or index.
versionnumberThe block version.
merklerootstringThe merkle root.
txarrayThe transaction ids.
timenumberThe block time in seconds since epoch.
noncenumberThe nonce.
bitsstringThe bits.
difficultynumberThe difficulty.
previousblockhashstringThe hash of the previous block.
nextblockhashstringThe hash of the next block.

Use Case

The getblock method is essential for:

  • Block explorers and chain analysis tools
  • Transaction verification and auditing
  • Historical data extraction
  • Block validation
  • Chain reorganization detection

Error Handling

Status CodeError MessageCause
403ForbiddenMissing or invalid ACCESS-TOKEN.
-5Block not foundInvalid block hash provided.

Integration Notes

The getblock method helps developers:

  • Build block explorer functionality
  • Verify transaction inclusion
  • Analyze block composition
  • Track chain progression
  • Extract mining statistics