Install
$ agentstack add skill-0gfoundation-0g-agent-skills-download-file ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ● Environment & secrets Used
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
Download File from 0G Storage
Metadata
- Category: storage
- SDK:
@0glabs/0g-ts-sdk^0.3.3,ethers^6.13.0 - Activation Triggers: "download file", "retrieve from 0G", "get file", "fetch from storage"
Purpose
Download and verify files from 0G decentralized storage using a root hash. Supports verified downloads with Merkle proof validation to ensure data integrity.
Prerequisites
- Node.js >= 18
@0glabs/0g-ts-sdkinstalled- Root hash of the file to download
.envwithSTORAGE_INDEXER
Quick Workflow
- Create an
Indexerinstance - Call
indexer.download()with the root hash, output path, and verified flag - The file is downloaded and optionally verified via Merkle proofs
Core Rules
ALWAYS
- Use verified downloads in production (third param =
true) - Validate root hash format before downloading
- Check output directory exists before download
- Handle download errors gracefully
NEVER
- Use unverified downloads for critical data
- Assume a root hash is valid without checking
- Download to paths without write permissions
Code Examples
Basic Download
import { Indexer } from '@0glabs/0g-ts-sdk';
import 'dotenv/config';
async function downloadFile(rootHash: string, outputPath: string): Promise {
const indexer = new Indexer(process.env.STORAGE_INDEXER!);
// Download with Merkle verification (recommended)
// Note: download() can throw errors (e.g., JsonRpcError) in addition to returning them
try {
const err = await indexer.download(rootHash, outputPath, true);
if (err) throw err;
} catch (error: any) {
throw new Error(`Download failed: ${error.message}`);
}
console.log(`Downloaded to ${outputPath}`);
}
// Usage
await downloadFile('0xabc123...', './downloads/my-file.pdf');
Download with Validation
import { Indexer } from '@0glabs/0g-ts-sdk';
import * as fs from 'fs';
import * as path from 'path';
import 'dotenv/config';
async function downloadWithValidation(rootHash: string, outputPath: string): Promise {
if (!process.env.STORAGE_INDEXER) {
throw new Error('STORAGE_INDEXER not set in .env');
}
// Validate root hash format
if (!rootHash.startsWith('0x') || rootHash.length ,
): Promise {
const indexer = new Indexer(process.env.STORAGE_INDEXER!);
const results = await Promise.allSettled(
files.map(async ({ rootHash, outputPath }) => {
const err = await indexer.download(rootHash, outputPath, true);
if (err) throw err;
}),
);
results.forEach((result, i) => {
if (result.status === 'fulfilled') {
console.log(`Downloaded: ${files[i].outputPath}`);
} else {
console.error(`Failed: ${files[i].rootHash} — ${result.reason}`);
}
});
}
Anti-Patterns
// BAD: Unverified download in production
await indexer.download(rootHash, outputPath, false);
// BAD: No error handling — download() can THROW in addition to returning errors
await indexer.download(rootHash, outputPath, true);
// If file doesn't exist, throws JsonRpcError!
// GOOD: Proper error handling
try {
const err = await indexer.download(rootHash, outputPath, true);
if (err) throw err;
} catch (error) {
console.error('Download failed:', error);
}
// BAD: Downloading to non-existent directory
await indexer.download(rootHash, '/nonexistent/path/file.txt', true);
Common Errors & Fixes
| Error | Cause | Fix | | ----------------------- | --------------------------------- | ------------------------------------ | | file not found | Invalid or non-existent root hash | Verify the root hash is correct | | verification failed | Data integrity check failed | Re-download or report issue | | ENOENT | Output directory doesn't exist | Create directory with fs.mkdirSync | | EACCES | No write permission | Check file system permissions | | indexer not available | Wrong indexer URL | Check STORAGE_INDEXER in .env |
Related Skills
- [Upload File](../upload-file/SKILL.md) — upload files to get root hashes
- [Merkle Verification](../merkle-verification/SKILL.md) — verify data integrity
- [Compute + Storage](../../cross-layer/compute-plus-storage/SKILL.md) — AI with storage I/O
References
- [Storage Patterns](../../../patterns/STORAGE.md)
- [Network Config](../../../patterns/NETWORK_CONFIG.md)
- 0G Storage SDK Docs
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: 0gfoundation
- Source: 0gfoundation/0g-agent-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.