Stellar Data Tool
A command line tool and REST API for querying the Stellar blockchain using public data lakes and RPC nodes, providing JSON formatted responses to simplify data availability.
Quick Start
Overview
This tool downloads Stellar ledger data from the public S3 bucket at s3://aws-public-blockchain/v1.1/stellar/ledgers/, decompresses the Zstandard compressed XDR data, and converts it to JSON format. If data isn't available (Most recent blocks) it falls back to querying an RPC node.
Available currently for Stellar mainnet only. Testnet coming soon (hopefully)
Published to: https://crates.io/crates/stellar-data
Features
- Dual Mode Operation: Use as CLI tool or REST API server
- Downloads ledger data directly from AWS S3 public data lake
- Automatically calculates correct S3 paths using partition and batch logic
- Decompresses Zstandard (.zst) compressed files
- Parses XDR (External Data Representation) format
- Converts to human-readable JSON
- Supports filtering for specific data types (transactions, all data, address-based)
- Query single ledgers or ranges of ledgers
- Query recent ledgers using negative values (e.g.,
-999for last 999 blocks) - Filter transactions by Stellar address
- REST API: HTTP endpoints for web application integration
- Smart Contract Queries: Filter by contract address or function name
- Token Balances: Query current balances with built-in token shortcuts
- Automatic RPC Fallback: Seamless fallback to RPC for most recent ledgers
Installation
Build from source
The binary will be available at ./target/release/stellar-data
Usage
The tool can be used in two modes:
- CLI Mode: Direct command-line queries with output to stdout
- REST API Mode: HTTP server exposing API endpoints
CLI Mode
Basic syntax:
|
Options
--ledger, -l: The ledger/block number or range to query (required)- Single ledger:
--ledger 63864 - Ledger range:
--ledger 63864-63900 - Recent ledgers (negative):
--ledger -999(queries last 999 blocks from current)
- Single ledger:
--query, -q: Query type -all,transactions, oraddress(default:all)--address, -a: Stellar address to filter by (required when--query address)
Examples
Get all data for a specific ledger
Output includes the full ledger close metadata:
- Ledger header information
- Transaction set
- Transaction processing details
- SCP (Stellar Consensus Protocol) info
- Upgrade processing
Get only transactions from a ledger
Output format:
Get early Stellar ledger (may have no transactions)
Query a range of ledgers for all transactions
Output format:
Query the most recent N ledgers
Get transactions from the last 10 blocks:
The tool will automatically fetch the current latest ledger from Horizon and work backwards.
Output format:
Search for transactions involving a specific address
Single ledger:
Ledger range:
Recent blocks with address filter:
The address filter searches for:
- Source accounts in transactions
- Source accounts in operations
- Destination accounts in payments
- Asset issuers in trust lines
- Trustors in trust operations
- And other address-related fields
Output format:
REST API Mode
Start the API server to enable HTTP access to Stellar blockchain data:
Or use the default port (80):
Once started, the server will display:
Stellar Data API Server
======================
Listening on http://0.0.0.0:3000
Available endpoints:
GET /help
GET /transactions?ledger=<LEDGER>&address=<ADDRESS>
GET /all?ledger=<LEDGER>
GET /contract?ledger=<LEDGER>&address=<CONTRACT>
GET /function?ledger=<LEDGER>&name=<FUNCTION>
GET /balance?address=<ADDRESS>&token=<TOKEN>
REST API Endpoints
All endpoints return JSON responses (except /help which returns HTML documentation).
GET /help
Returns an interactive HTML documentation page with detailed information about all endpoints.
Or visit http://localhost:3000/help in your browser for a formatted documentation page.
GET /transactions
Get transactions from specified ledger(s), optionally filtered by address.
Parameters:
ledger(required): Ledger sequence number, range, or negative valueaddress(optional): Stellar address to filter transactions
Examples:
# Single ledger
# Ledger range
# Recent ledgers
# Filter by address
Response:
GET /all
Get complete ledger metadata including all transaction processing details.
Parameters:
ledger(required): Ledger sequence number, range, or negative value
Examples:
# Single ledger
# Ledger range
# Recent ledgers
Response:
GET /contract
Get transactions involving a specific smart contract.
Parameters:
ledger(required): Ledger sequence number, range, or negative valueaddress(required): Contract address (starts with 'C')
Examples:
# Search contract invocations in ledger range
# Search recent ledgers
Response:
GET /function
Get transactions calling a specific contract function by name.
Parameters:
ledger(required): Ledger sequence number, range, or negative valuename(required): Function name (e.g., 'transfer', 'approve', 'mint')
Examples:
# Search for transfer function calls
# Search recent ledgers for approve calls
Response:
GET /balance
Get current token balance for a Stellar address using RPC.
Parameters:
address(required): Stellar account addresstoken(required): Token contract address or shortcut
Token Shortcuts:
xlm- Native Stellar Lumensusdc- USD Coinusdt- Tether USDaqua- Aquarius tokenbtc- Bitcoin (wrapped)
Examples:
# Get XLM balance
# Get USDC balance
# Get balance for specific token contract
Response:
REST API Features
- CORS Enabled: The API has permissive CORS enabled for easy integration with web applications
- Automatic Fallback: Recent ledgers automatically fall back to RPC when not available in S3
- Error Resilience: Individual ledger failures in ranges don't stop processing
- Interactive Documentation: Visit
/helpendpoint in a browser for full interactive documentation
REST API vs CLI Mode
| Feature | CLI Mode | REST API Mode |
|---|---|---|
| Use Case | One-time queries, scripts, automation | Web applications, continuous access, integration |
| Output | stdout (console) | HTTP JSON responses |
| Concurrency | Single query per invocation | Multiple concurrent requests |
| Setup | Run directly | Start server once |
| Documentation | --help flag |
Interactive /help endpoint |
How It Works
URL Generation
The tool calculates the S3 URL based on the ledger sequence number using the following format:
https://aws-public-blockchain.s3.us-east-2.amazonaws.com/v1.1/stellar/ledgers/pubnet/{PARTITION}/{BATCH}.xdr.zst
Where:
- Partition: Groups of 64,000 ledgers formatted as
FFFFFFFF--{start}-{end} - Batch: Individual ledgers (batch size = 1) formatted as
FFFFFFFF--{ledger}.xdr.zst
Example for ledger 63864:
FFFFFFFF--0-63999/FFFF0687--63864.xdr.zst
The hexadecimal values are calculated as 0xFFFFFFFF - ledger_sequence.
Data Processing Pipeline
- Fetch Latest Ledger (if using negative values): Queries Stellar Horizon API for current ledger
- Download: Fetches compressed XDR data from S3
- Decompress: Uses Zstandard decompression
- Parse: Decodes XDR into
LedgerCloseMetaBatchstructure - Convert: Serializes to JSON using the stellar-xdr crate's serde support
Configuration
The tool uses these default values from the S3 data lake configuration:
- Network: Public Global Stellar Network (mainnet)
- Compression: Zstandard
- Ledgers per batch: 1
- Batches per partition: 64,000
- Base URL:
https://aws-public-blockchain.s3.us-east-2.amazonaws.com
Data Structure
The XDR files contain LedgerCloseMetaBatch structures with:
Each LedgerCloseMeta can be V0, V1, or V2 format, containing:
- Ledger header with sequence number, timestamps, hashes
- Transaction set with all transactions in the ledger
- Transaction processing results
- Upgrade processing information
- SCP consensus information
Publishing Notes
There's a bug in WSL that prevents metadata, use Windows console
References
License
MIT
Contributions
Feel free to improve and put in a pull request ♥️