Observed since 20 Oct, 22:11 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
JS SDK for 0G Storage
This is the JavaScript SDK for 0g-storage. Features include:
npm install @0glabs/0g-ts-sdk ethers
ethers is a peer dependency of this project.
Use ZgFile to create a file object, then call merkleTree method to get the merkle tree of the file.
import { Indexer, ZgFile } from '@0glabs/0g-ts-sdk';
import { ethers } from 'ethers';
import { exit } from 'process';
const file = await ZgFile.fromFilePath(<file_path>);
var [tree, err] = await file.merkleTree();
if (err === null) {
console.log("File Root Hash: ", tree.rootHash());
} else {
exit(1);
}
await file.close();
Upload file to 0g-storage:
import { getFlowContract } from '@0glabs/0g-ts-sdk';
const evmRpc = 'https://evmrpc-testnet.0g.ai';
const privateKey = ''; // with balance to pay for gas
const indRpc = 'https://indexer-storage-testnet-turbo.0g.ai'; // indexer rpc
const provider = new ethers.JsonRpcProvider(evmRpc);
const signer = new ethers.Wallet(privateKey, provider);
const indexer = new Indexer(indRpc);
// need to pay fees to store data in storage nodes
var [tx, err] = await indexer.upload(file, evmRpc, signer);
if (err === null) {
console.log("File uploaded successfully, tx: ", tx);
} else {
console.log("Error uploading file: ", err);
}
Download file from 0g-storage
err = await indexer.download(<root_hash>, <output_file>, <with_proof>);
if (err !== null) {
console.log("Error downloading file: ", err);
}
Upload data to 0g-kv:
var [nodes, err] = await indexer.selectNodes(1);
if (err !== null) {
console.log("Error selecting nodes: ", err);
stop();
}
const batcher = new Batcher(1, nodes, flowContract, evmRpc);
const key1 = Uint8Array.from(Buffer.from("TESTKEY0", 'utf-8'));
const val1 = Uint8Array.from(Buffer.from("TESTVALUE0", 'utf-8'));
const key2 = Uint8Array.from(Buffer.from("TESTKEY1", 'utf-8'));
const val2 = Uint8Array.from(Buffer.from("TESTVALUE1", 'utf-8'));
batcher.streamDataBuilder.set("0x...", key1, val1);
batcher.streamDataBuilder.set("0x...", key2, val2);
var [tx, err] = await batcher.exec();
if (err === null) {
console.log("Batcher executed successfully, tx: ", tx);
} else {
console.log("Error executing batcher: ", err);
}
Download data from 0g-kv
const KvClientAddr = "http://3.101.147.150:6789"
const streamId = "0x..."
const kvClient = new KvClient(KvClientAddr)
let val = await kvClient.getValue(streamId, ethers.encodeBase64(key1));
console.log(val)
Import zgstorage.esm.js in your html file:
<script type="module">
import { Blob, Indexer } from "./dist/zgstorage.esm.js";
// Your code here...
</script>
Create file object from blob:
const file = new Blob(blob);
const [tree, err] = await file.merkleTree();
if (err === null) {
console.log("File Root Hash: ", tree.rootHash());
}
File upload is same with node.js environment with the following provider change
import { BrowserProvider } from 'ethers'; // or from ethers.js url
let provider = new BrowserProvider(window.ethereum) // metamask need to be installed
To use the SDK with Vite, set up polyfills in your vite.config.ts:
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
export default defineConfig({
plugins: [
...
nodePolyfills({
include: ['crypto', 'buffer', 'stream', 'util', 'events'],
}),
],
});
Now, you can import SDK files with the /browser suffix:
import { Indexer, Blob } from '@0glabs/0g-ts-sdk/browser';
Check codes in examples for more details.
This project uses pnpm as package manager. After cloning the project, run pnpm install to install dependencies.
Make sure 0g-storage-contracts is in project sibling directory.
pnpm gen-contract-type-flow
pnpm gen-contract-type-market
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.3.3Registry latest | 22 Oct 2025 | 19 | |
| 0.3.2 | 16 Oct 2025 | 19 | |
| 0.3.1 | 19 Aug 2025 | 19 | |
| 0.3.0 | 22 Apr 2025 | 19 | |
| 0.2.9 | 27 Mar 2025 | 19 | |
| 0.2.8 | 25 Mar 2025 | 19 | |
| 0.2.7 | 19 Mar 2025 | 19 | |
| 0.2.6 | 20 Feb 2025 | 19 | |
| 0.2.5 | 12 Feb 2025 | 19 | |
| 0.2.4 | 12 Feb 2025 | 19 | |
| 0.2.3 | 3 Dec 2024 | 19 | |
| 0.2.2 | 27 Nov 2024 | 19 | |
| 0.2.1 | 5 Sept 2024 | 19 | |
| 0.2.0 | 3 Sept 2024 | 19 | |
| 0.1.2 | 2 Aug 2024 | 19 | |
| 0.1.1 | 29 Jul 2024 | 19 | |
| 0.1.0 | 25 Jul 2024 | 19 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 22:11 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:7170df93aed69d9ee1760d7cb61eb1a14a8c70513826095e83ca8bfd36b3e64d