What you can do with the SDK
- Upload & download files — with automatic shard routing, retry logic, and merkle verification
- Generate merkle trees — produce cryptographic proofs of file integrity with byte-exact parity to the TypeScript SDK
- Store large files — split uploads into 4 GB fragments, then download and reassemble
- Read & write KV data — append-only key-value streams with per-key access control
- Inspect storage nodes — low-level RPC access for segment uploads, downloads, and shard configs
Core primitives
- Files — any byte stream, chunked into 256-byte leaves and organized into a merkle tree
- Merkle proofs — Keccak256-based proofs that bind every byte to a single root hash
- Streams — KV data stores identified by a
stream_id, with read/write/admin access control - Flow contract — the on-chain submission registry that records file metadata and triggers storage node propagation
How it works
Build the merkle tree
The SDK reads your file, splits it into 256-byte chunks, and computes a merkle tree. The root hash identifies the file globally.
Submit to the Flow contract
The SDK sends a transaction to the Flow contract with the file’s root hash, size, and tags. Storage nodes watch the contract and begin ingesting.
Upload segments to sharded nodes
File segments are uploaded in parallel to the selected storage nodes, with automatic retry on transient failures.
Why 0G Storage
- Verifiable — every file is anchored by a merkle root; no trust in individual nodes required
- Sharded — files are spread across nodes by shard ID for capacity and redundancy
- Compatible — byte-exact parity with the TypeScript SDK, so files uploaded with either SDK produce identical root hashes
- Large-file ready — splitable uploads handle multi-gigabyte files natively
- Structured storage — a full KV layer for indexed data, not just blobs
Storage vs. KV
The SDK exposes two storage primitives through the same network:| Use case | Primitive | Key class |
|---|---|---|
| Store a file or blob as a whole | File upload | Indexer, ZgFile |
| Store discrete key → value pairs, read by key | KV streams | KvClient, StreamDataBuilder |
Next steps
Install the SDK
Install
0g-storage-sdk and configure network endpoints.Upload & download
Your first file upload and download, end-to-end.
For protocol-level details, see the official 0G Labs documentation.