sdk.infrastructure
Encrypted decentralized storage and compute via Gao DePIN nodes. Data is content-addressed, redundant, and encrypted by default.
Storage — Upload
const cap = await sdk.developer.capability.request('infrastructure:storage:write', 'myapp.gao')
const receipt = await sdk.infrastructure.storage.upload(
data, // Uint8Array | string
{
encrypted?: true, // default true
ttl_days?: 30, // null = permanent
redundancy?: 3, // copies across nodes, default 3
content_type?: 'application/pdf',
}
)
console.log(receipt.cid) // content-addressed ID e.g. "bafy..."
console.log(receipt.size) // bytes
cid is derived from the content hash — identical content always produces the same CID.
Storage — Download
const data = await sdk.infrastructure.storage.download(cid)
// → Uint8Array
// Convert to File for browser download
const blob = new Blob([data], { type: 'application/pdf' })
const url = URL.createObjectURL(blob)
---
### Storage — Delete & Pin
// Delete (if TTL hasn't expired yet)
await sdk.infrastructure.storage.delete(cid)
// Pin (make permanent — overrides TTL)
await sdk.infrastructure.storage.pin(cid)
Storage Receipt
interface StorageReceipt {
cid: string // content ID
size: number // bytes
encrypted: boolean
redundancy: number // actual copies stored
nodes: string[] // node IDs that hold the data
expires_at?: number // unix timestamp, null if permanent
signature: string // cryptographic proof of storage
}
---
### Compute — Submit Job
For heavy computation that shouldn’t run on your server:
const cap = await sdk.developer.capability.request('infrastructure:compute:allocate', 'myapp.gao')
const job = await sdk.infrastructure.compute.submit({
runtime: 'python', // 'python' | 'node' | 'wasm'
code: `
import json, sys
data = json.loads(sys.stdin.read())
result = sum(data['numbers'])
print(json.dumps({'sum': result}))
`,
input: { numbers: [1, 2, 3, 4, 5] },
timeout_seconds: 30,
capability: cap.token,
})
console.log(job.job_id)
Compute — Get Result
// Poll for result
const result = await sdk.infrastructure.compute.getResult(job.job_id)
// result.status — 'pending' | 'running' | 'completed' | 'failed'
// result.output — parsed output from your code
// result.receipt — compute receipt for billing/audit
// Validate receipt
const valid = await sdk.infrastructure.compute.validateReceipt(result.receipt)
---
### Compute Receipt
interface ComputeReceipt {
job_id: string
node_id: string // which DePIN node executed
runtime: string
duration_ms: number
cpu_seconds: number
memory_peak_mb: number
cost: string // in GAO tokens
signature: string // node's cryptographic proof of execution
}
Common Patterns
Encrypted Document Vault
// Upload
async function storeDocument(file: File): Promise<string> {
const buffer = await file.arrayBuffer()
const receipt = await sdk.infrastructure.storage.upload(
new Uint8Array(buffer),
{ encrypted: true, ttl_days: 365, content_type: file.type }
)
return receipt.cid
}
// Download
async function retrieveDocument(cid: string): Promise<Blob> {
const data = await sdk.infrastructure.storage.download(cid)
return new Blob([data])
}
PDF Report Generation
// Run Python code on DePIN to generate PDF
const job = await sdk.infrastructure.compute.submit({
runtime: 'python',
code: generatePDFScript,
input: salesData,
timeout_seconds: 60,
capability: cap.token,
})
const result = await sdk.infrastructure.compute.getResult(job.job_id)
const pdfCid = result.output.pdf_cid
// Download generated PDF
const pdf = await sdk.infrastructure.storage.download(pdfCid)
User-Controlled Backup
// User opts into GaoStorage backup
async function enableBackup(storageMode: 'none' | 'local' | 'depin') {
if (storageMode === 'depin') {
// Upload user's encrypted data
const receipt = await sdk.infrastructure.storage.upload(
encryptedUserData,
{ encrypted: true, redundancy: 3 }
)
// Store CID so user can restore later
await saveUserCID(receipt.cid)
}
}
---
### Storage Tiers
Mode
Location
Cost
Privacy
`none` (default)
RAM only
Free
Maximum
`local`
Device encrypted storage
Free
High
`depin`
GaoStorage nodes
Pay per GB
High (E2EE)
Users choose their storage mode. Gao Infrastructure cannot read encrypted content.
---