AI Coding Context
This page provides comprehensive context about 0G infrastructure to help AI coding assistants help developers build on 0G. All information is extracted from the official documentation at https://docs.0g.ai.
Network Configurations
Testnet (Galileo)
Explorer: https://explorer.0g.ai/testnet/home
| Parameter | Value |
|---|---|
| Network Name | 0G Galileo Testnet |
| Chain ID | 16602 |
| Token Symbol | 0G |
| RPC Endpoint | https://evmrpc-testnet.0g.ai (development only — use 3rd party RPCs for production) |
| Block Explorer | https://chainscan-galileo.0g.ai |
| Storage Explorer | https://storagescan-galileo.0g.ai |
| Faucet | https://faucet.0g.ai (0.1 0G/day) |
| Faucet (Google Cloud) | https://cloud.google.com/application/web3/faucet/0g/galileo |
| Storage Indexer | https://indexer-storage-testnet-turbo.0g.ai (API base URL; root / may return 404) |
| Storage Start Block | 1 |
| DA Start Block | 940000 |
Documentation: https://docs.0g.ai/developer-hub/testnet/testnet-overview
Third-Party RPCs (Recommended for Production):
- QuickNode: https://www.quicknode.com/chains/0g
- ThirdWeb: https://thirdweb.com/16602
- Ankr: https://www.ankr.com/rpc/0g/
- dRPC: https://drpc.org/chainlist/0g-galileo-testnet-rpc
- dRPC NodeCloud: https://drpc.org/chainlist/0g-galileo-testnet-rpc
Mainnet (Aristotle)
Explorer: https://explorer.0g.ai/mainnet/home
| Parameter | Value |
|---|---|
| Network Name | 0G Mainnet |
| Chain ID | 16661 |
| Token Symbol | 0G |
| RPC Endpoint | https://evmrpc.0g.ai |
| Storage Indexer | https://indexer-storage-turbo.0g.ai (API base URL; root / may return 404) |
| Block Explorer | https://chainscan.0g.ai |
| Storage Start Block | 2387557 |
Documentation: https://docs.0g.ai/developer-hub/mainnet/mainnet-overview
Third-Party RPCs (Recommended for Production):
- QuickNode: https://www.quicknode.com/chains/0g
- ThirdWeb: https://thirdweb.com/0g-aristotle
- Ankr: https://www.ankr.com/rpc/0g/
- dRPC: https://drpc.org/chainlist/0g-mainnet-rpc
Smart Contract Addresses
Testnet Contracts
| Contract | Address | Purpose |
|---|---|---|
| Flow | 0x22E03a6A89B950F1c82ec5e74F8eCa321a105296 | Storage data flow management |
| Mine | 0x00A9E9604b0538e06b268Fb297Df333337f9593b | Storage mining rewards |
| Reward | 0xA97B57b4BdFEA2D0a25e535bd849ad4e6C440A69 | Reward distribution |
| DAEntrance | not published; ask the DA team | DA blob submission. The previously documented testnet addresses have no code on Galileo, so none is listed here |
| DASigners | 0x0000000000000000000000000000000000001000 | DA signer management (precompile) |
| WrappedOGBase | 0x0000000000000000000000000000000000001002 | Wrapped native token (precompile) |
| Compute Ledger | 0xE70830508dAc0A97e6c087c75f402f9Be669E406 | Compute network payment ledger |
| Compute Inference | 0xa79F4c8311FF93C06b8CfB403690cc987c93F91E | Compute inference service |
| Compute FineTuning | 0xC6C075D8039763C8f1EbE580be5ADdf2fd6941bA | Compute fine-tuning service (fine-tuning-v1.1) |
The previous testnet fine-tuning contract (0xaC66eBd174435c04F1449BBa08157a707B6fa7b1, registered as fine-tuning-v1.0) is still deployed and still registered on the Ledger, but it runs an older ABI. Use fine-tuning-v1.1 for new integrations; historical indexers covering data before 2026-02-12 still need the old address.
Mainnet Contracts
| Contract | Address | Purpose |
|---|---|---|
| Flow | 0x62D4144dB0F0a6fBBaeb6296c785C71B3D57C526 | Storage data flow management |
| Mine | 0xCd01c5Cd953971CE4C2c9bFb95610236a7F414fe | Storage mining rewards |
| Reward | 0x457aC76B58ffcDc118AABD6DbC63ff9072880870 | Reward distribution |
| DASigners | 0x0000000000000000000000000000000000001000 | DA signer management (precompile) |
| WrappedOGBase | 0x0000000000000000000000000000000000001002 | Wrapped native token (precompile) |
| Compute Ledger | 0x2dE54c845Cd948B72D2e32e39586fe89607074E3 | Compute network payment ledger |
| Compute Inference | 0x47340d900bdFec2BD393c626E12ea0656F938d84 | Compute inference service |
| Compute FineTuning | 0x4e3474095518883744ddf135b7E0A23301c7F9c0 | Compute fine-tuning service |
$0G Token Contracts
$0G is the native gas token on 0G Mainnet (no contract address). Official token contract representations:
| Network (chain ID) | Token | Address |
|---|---|---|
| 0G Mainnet (16661) | W0G — Wrapped 0G | 0x1Cd0690fF9a693f5EF2dD976660a8dAFc81A109c |
| Ethereum (1) | 0G — official bridged token | 0x4B948d64dE1F71fCd12fB586f4c776421a35b3eE |
| BNB Chain (56) | 0G — official bridged token | 0x4B948d64dE1F71fCd12fB586f4c776421a35b3eE |
All 18 decimals. The bridged token shares the same address on Ethereum and BNB Chain (bridged via Stargate). Any other contract claiming to be $0G is not official.
0G Services Overview
0G Chain
Documentation: https://docs.0g.ai/concepts/chain
AI-native EVM L1 chain with 11,000 TPS per Shard, sub-second finality, and full EVM compatibility.
Key Features:
- Full EVM compatibility - Use existing Ethereum tools (Hardhat, Foundry, Remix)
- 11,000 TPS per Shard with sub-second finality
- Same as Ethereum development - just different RPC endpoint
- Optimized CometBFT consensus
- Native precompiled contracts for DA and wrapped tokens
Deploy Smart Contracts:
Using Hardhat:
// hardhat.config.js
module.exports = {
networks: {
testnet: {
url: "https://evmrpc-testnet.0g.ai",
chainId: 16602,
accounts: ["YOUR_PRIVATE_KEY"]
},
mainnet: {
url: "https://evmrpc.0g.ai",
chainId: 16661,
accounts: ["YOUR_PRIVATE_KEY"]
}
},
solidity: "0.8.20"
};
Using Foundry:
# Testnet
forge create --rpc-url https://evmrpc-testnet.0g.ai \
--private-key YOUR_PRIVATE_KEY \
src/MyContract.sol:MyContract
# Mainnet
forge create --rpc-url https://evmrpc.0g.ai \
--private-key YOUR_PRIVATE_KEY \
src/MyContract.sol:MyContract
Using Remix:
- Open Remix IDE
- Compile your contract
- Go to Deploy & Run Transactions
- Select "Injected Provider - MetaMask"
- Ensure MetaMask is connected to 0G network
- Deploy!
Precompiled Contracts:
DASigners (0x0000000000000000000000000000000000001000):
// Query DA signers, quorums and epochs
function epochNumber() external view returns (uint);
function quorumCount(uint _epoch) external view returns (uint);
function isSigner(address _account) external view returns (bool);
function getSigner(address[] memory _account) external view returns (SignerDetail[] memory);
function getQuorum(uint _epoch, uint _quorumId) external view returns (address[] memory);
function getQuorumRow(uint _epoch, uint _quorumId, uint32 _rowIndex) external view returns (address);
function registeredEpoch(address _account, uint _epoch) external view returns (bool);
WrappedOGBase (0x0000000000000000000000000000000000001002):
// Quota-based wrapper for native 0G; not a WETH-style deposit/withdraw interface.
struct Supply {
uint256 cap; // maximum allowed mint supply for the minter
uint256 initialSupply; // initial mint supply, also the initial allowed burn amount
uint256 supply; // current mint supply used by the minter
}
function getWA0GI() external view returns (address);
function minterSupply(address minter) external view returns (Supply memory);
function mint(address minter, uint256 amount) external; // only callable by the WA0GI contract
function burn(address minter, uint256 amount) external; // only callable by the WA0GI contract
Verification & Indexing:
- Goldsky: GraphQL indexing and real-time data streaming
Documentation Links:
- Deploy Contracts: https://docs.0g.ai/developer-hub/building-on-0g/contracts-on-0g/deploy-contracts
- Precompiles: https://docs.0g.ai/developer-hub/building-on-0g/contracts-on-0g/precompiles/overview
- Staking: https://docs.0g.ai/developer-hub/building-on-0g/contracts-on-0g/staking-interfaces
- Validator Contracts: https://docs.0g.ai/developer-hub/building-on-0g/contracts-on-0g/validator-contract-functions
0G Storage
Documentation: https://docs.0g.ai/concepts/storage
Decentralized storage offering 95% lower costs than AWS with instant retrieval.
Key Features:
- 95% cheaper than centralized alternatives
- 200 MBPS retrieval speed
- Proven TB-scale operations
- Two storage layers: Log (immutable) + KV (mutable)
- Proof of Random Access (PoRA) consensus
Flow Contract Note: The Flow contract (log_contract_address) manages on-chain data flow for storage operations. For TypeScript SDK file uploads, the flow contract is handled internally by the Indexer — you only need the EVM RPC URL. For KV operations, the flow contract address is still required when constructing a Batcher. For Go SDK, the indexer client also handles flow contract interaction internally. The flow contract addresses are listed in the contract tables above.
SDK Installation:
TypeScript/JavaScript:
npm install @0gfoundation/0g-storage-ts-sdk ethers
Go:
go get github.com/0gfoundation/0g-storage-client
Starter Kits (recommended for getting started quickly):
- TypeScript: https://github.com/0gfoundation/0g-storage-ts-starter-kit — CLI scripts (
npm run upload), importable library (uploadFile,downloadFile,uploadData,batchUpload), and browser UI with MetaMask. Supports turbo/standard storage modes. - Go: https://github.com/0gfoundation/0g-storage-go-starter-kit
Quick Start Examples:
TypeScript - Upload File:
import { ZgFile, Indexer } from "@0gfoundation/0g-storage-ts-sdk";
import { ethers } from "ethers";
const provider = new ethers.JsonRpcProvider("https://evmrpc-testnet.0g.ai");
const signer = new ethers.Wallet("YOUR_PRIVATE_KEY", provider);
const indexer = new Indexer("https://indexer-storage-testnet-turbo.0g.ai");
// Upload — flow contract is resolved internally by the Indexer
const file = await ZgFile.fromFilePath("/path/to/file");
const [tree, treeErr] = await file.merkleTree();
console.log("Root Hash:", tree?.rootHash());
const [tx, uploadErr] = await indexer.upload(file, "https://evmrpc-testnet.0g.ai", signer);
await file.close();
TypeScript - KV Operations (requires flow contract):
import { Batcher, KvClient } from "@0gfoundation/0g-storage-ts-sdk";
// KV upload needs the flow contract address
const batcher = new Batcher(1, nodes, flowContract, RPC_URL);
batcher.streamDataBuilder.set(streamId, keyBytes, valueBytes);
const [tx, err] = await batcher.exec();
// KV read
const kvClient = new KvClient("<kv_node_url>");
const value = await kvClient.getValue(streamId, encodedKey);
CLI Tool (Go — built from 0g-storage-client):
# Install
git clone https://github.com/0gfoundation/0g-storage-client.git
cd 0g-storage-client
go build
# Upload file
0g-storage-client upload \
--url https://evmrpc-testnet.0g.ai \
--key YOUR_PRIVATE_KEY \
--indexer https://indexer-storage-testnet-turbo.0g.ai \
--file /path/to/file
# Upload with client-side encryption (AES-256-CTR)
0g-storage-client upload \
--url https://evmrpc-testnet.0g.ai \
--key YOUR_PRIVATE_KEY \
--indexer https://indexer-storage-testnet-turbo.0g.ai \
--file /path/to/file \
--encryption-key <hex_key>
# Download file (--proof enables merkle verification)
0g-storage-client download \
--indexer https://indexer-storage-testnet-turbo.0g.ai \
--root <ROOT_HASH> \
--file output.dat \
--proof
# KV write
0g-storage-client kv-write \
--url https://evmrpc-testnet.0g.ai \
--key YOUR_PRIVATE_KEY \
--indexer https://indexer-storage-testnet-turbo.0g.ai \
--stream-id <STREAM_ID> \
--stream-keys <KEYS> \
--stream-values <VALUES>
# KV read
0g-storage-client kv-read \
--node <KV_NODE_URL> \
--stream-id <STREAM_ID> \
--stream-keys <KEYS>
Indexer REST API (HTTP gateway for file operations):
GET /file?root=0x... # Download file by merkle root
GET /file?txSeq=7 # Download file by tx sequence
GET /file/{root}/path/to/file # Download file from folder
GET /file/info/{cid} # Query file info
POST /file/segment # Upload file segment (JSON: txSeq/root, index, data, proof)
The storage indexer URLs above are API base URLs. The root path (/) is not a
health endpoint and can return 404; use an API route such as
/file/info/{cid} when checking indexer availability.
Documentation Links:
- SDK Guide: https://docs.0g.ai/developer-hub/building-on-0g/storage/sdk
- CLI Guide: https://docs.0g.ai/developer-hub/building-on-0g/storage/storage-cli
GitHub Repositories:
- Storage Node: https://github.com/0gfoundation/0g-storage-node
- Storage KV: https://github.com/0gfoundation/0g-storage-kv
- Go Client/CLI: https://github.com/0gfoundation/0g-storage-client
- TypeScript SDK: https://github.com/0gfoundation/0g-storage-ts-sdk
0G Compute
Documentation: https://docs.0g.ai/concepts/compute
Decentralized GPU marketplace offering 90% cheaper AI workloads with OpenAI SDK compatibility.
Key Features:
- 90% cost reduction vs traditional cloud (e.g., 0.03 per 1K tokens)
- Pay-per-use pricing (no subscriptions or monthly minimums)
- OpenAI SDK compatible - drop-in replacement
- Smart contract escrow for trustless payments
- TEE (Trusted Execution Environment) for secure processing
- 50-100ms inference latency
- Supports: Chatbot (LLM), Text-to-Image, Speech-to-Text
DePIN Partners:
- io.net: 300,000+ GPUs across 139 countries
- Aethir: 43,000+ enterprise-grade GPUs, 3,000+ H100s/H200s
Two Integration Paths:
- Router (recommended) — a single OpenAI-compatible API endpoint (
https://router-api.0g.ai/v1) with one unified balance, automatic provider failover, and an API key. Best for server-side apps, agents, prototypes. Web UI: pc.0g.ai. - Direct — connect to individual providers via the
@0gfoundation/0g-compute-ts-sdkSDK, manage per-provider sub-accounts, sign each request with your wallet. Best for browser dApps with wallet signing or direct on-chain control. Web UI: compute-marketplace.0g.ai (or Advanced mode on pc.0g.ai).
The two balance pools are independent — a Router deposit does not fund Direct sub-accounts and vice versa.
Quick Start — Router (Recommended):
# 1. Visit https://pc.0g.ai, connect wallet, deposit 0G tokens
# 2. Dashboard → API Keys → create a key with 'inference' permission (starts with sk-)
# 3. Send a request — any OpenAI-compatible client works:
curl https://router-api.0g.ai/v1/chat/completions \
-H "Authorization: Bearer sk-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"messages": [{"role": "user", "content": "Hello!"}]
}'
OpenAI SDK Integration (Router):
from openai import OpenAI
client = OpenAI(
base_url="https://router-api.0g.ai/v1",
api_key="sk-YOUR_API_KEY"
)
response = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "Hello!"}]
)
Router also supports: image generation via POST /v1/images/generations (OpenAI-compatible, sync) or POST /v1/async/images/generations + GET /v1/async/jobs/{jobId}?provider_address=... (recommended for production) — both paths must pass "response_format": "b64_json" today; URL responses will be added later. Also /v1/audio/transcriptions, provider routing via X-0G-Provider-* request headers (X-0G-Provider-Sort: latency/price, X-0G-Provider-Address: 0x… to pin, or X-0G-Provider-Max-Price-Usd-Prompt/-Completion/-Image to cap per-request price — header-only, malformed values return 400), GET /v1/models (no auth), GET /v1/account/balance, GET /v1/account/usage/{stats,history}. The Router also serves the Anthropic Messages API (POST /v1/messages): set ANTHROPIC_BASE_URL=https://router-api.0g.ai to point Anthropic SDKs or Claude Code at it; models listing "anthropic" in supported_formats on GET /v1/models support this format.
Quick Start — Direct (SDK):
# Install CLI
pnpm add @0gfoundation/0g-compute-ts-sdk -g
# Setup + fund
0g-compute-cli setup-network
0g-compute-cli login # prompts for wallet private key
0g-compute-cli deposit --amount 10
0g-compute-cli inference list-providers
0g-compute-cli transfer-fund --provider <PROVIDER_ADDRESS> --amount 5 # auto-acknowledges
# Get a per-provider secret key
0g-compute-cli inference get-secret --provider <PROVIDER_ADDRESS>
With the per-provider secret, you call the provider's proxy directly:
from openai import OpenAI
client = OpenAI(
base_url="<service_url>/v1/proxy",
api_key="app-sk-<YOUR_SECRET>",
)
Fine-tuning Models (uses the Direct account system; not available via Router):
# Prepare dataset (JSONL format, one {"prompt": "...", "completion": "..."} per line)
0g-compute-cli fine-tuning upload-data --file dataset.jsonl
# Create fine-tuning task (fund the fine-tuning sub-account first: transfer-fund --service fine-tuning)
0g-compute-cli fine-tuning create-task \
--model Qwen2.5-0.5B-Instruct \
--dataset <DATASET_ID> \
--provider <PROVIDER_ADDRESS>
# Monitor progress
0g-compute-cli fine-tuning get-task --task-id <TASK_ID>
Documentation Links:
- Overview: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/overview
- Router (recommended):
- Overview: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/router/overview
- Quickstart: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/router/quickstart
- Models: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/router/models
- Chat Completions: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/router/features/chat-completions
- Claude Code (Anthropic API): https://docs.0g.ai/developer-hub/building-on-0g/compute-network/router/clients/claude-code
- Provider Routing: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/router/routing
- Deposits & Billing: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/router/account/deposits
- Router vs Direct: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/router/comparison
- Direct (SDK):
- Fine-tuning: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/fine-tuning
- Provider Setup: https://docs.0g.ai/developer-hub/building-on-0g/compute-network/inference-provider
0G DA (Data Availability)
Documentation: https://docs.0g.ai/concepts/da
Scalable data availability layer for rollups with 50 Gbps throughput.
Key Features:
- 50 Gbps demonstrated throughput
- VRF-based node selection
- Inherits Ethereum security
For Rollup Developers:
- OP Stack Integration: https://docs.0g.ai/developer-hub/building-on-0g/rollups-and-appchains/op-stack-on-0g-da
- Arbitrum Nitro: https://docs.0g.ai/developer-hub/building-on-0g/rollups-and-appchains/arbitrum-nitro-on-0g-da
- Integration Guide: https://docs.0g.ai/developer-hub/building-on-0g/da-integration
Agentic ID (formerly INFT)
Documentation: https://docs.0g.ai/concepts/agentic-id
Agentic ID is the rebrand of what was previously called INFT (Intelligent NFT). ERC-7857 is the underlying NFT standard for tokenizing AI agents. It extends ERC-721 with encrypted metadata, secure re-encryption on transfer via TEE/ZKP oracles, cloning, and usage authorization. The reference implementation uses upgradeable beacon proxies and OpenZeppelin AccessControl. 0G also officially supports ERC-8004 (Trustless Agents) for public on-chain agent identity and discoverability, and Agentic ID is ERC-8004 compatible (see the ERC-8004 section below).
GitHub Repository: https://github.com/0gfoundation/0g-agent-nft
Core Interface (IERC7857):
interface IERC7857 is IERC721, IERC7857Metadata {
// Transfer token with encrypted metadata re-encryption
function iTransferFrom(
address _from,
address _to,
uint256 _tokenId,
TransferValidityProof[] calldata _proofs
) external;
// Delegate access-proof signing to an assistant address
function delegateAccess(address _assistant) external;
// Get the verifier contract (TEE or ZKP oracle)
function verifier() external view returns (IERC7857DataVerifier);
}
Key Data Structures:
struct IntelligentData {
string dataDescription;
bytes32 dataHash;
}
struct TransferValidityProof {
AccessProof accessProof; // Signed by receiver
OwnershipProof ownershipProof; // Signed by TEE/ZKP oracle
}
struct OwnershipProof {
OracleType oracleType; // TEE or ZKP
bytes32 dataHash;
bytes sealedKey; // Encryption key sealed for receiver
bytes targetPubkey;
bytes nonce;
bytes proof;
}
enum OracleType { TEE, ZKP }
Extensions:
- Cloneable (
IERC7857Cloneable):iCloneFrom()— creates a new token with the same encrypted metadata - Authorize (
IERC7857Authorize):authorizeUsage()/revokeAuthorization()— grant usage rights without ownership transfer (max 100 users per token, cleared on transfer) - Data Storage (
ERC7857IDataStorageUpgradeable): On-chain storage for arrays ofIntelligentDataper token
Architecture:
- AgentNFT: Main contract — minting, creator tracking, mint fees. Roles:
ADMIN_ROLE,OPERATOR_ROLE,MINTER_ROLE - Verifier: Orchestrates TEE/ZKP proof verification with replay protection (nonce-based, 7-day expiry)
- TeeVerifier: ECDSA signature verification against a registered TEE oracle address
- AgentMarket: Marketplace with order/offer model, EIP-712 signatures, platform + partner fee distribution, and native/ERC20 payment support
Transfer Flow:
- Receiver signs
AccessProof(proving they want the data) - TEE/ZKP oracle decrypts metadata, re-encrypts with receiver's public key, produces
OwnershipProofwithsealedKey iTransferFrom()callsverifier.verifyTransferValidity()to validate both proofs- Token ownership transfers and
PublishedSealedKeyevent emits for receiver to decrypt
Use Cases: AI Trading Bots, Personal Assistants, Game Characters, Content Creation AI, Research Tools
Documentation Links:
- Agentic ID Overview: https://docs.0g.ai/developer-hub/building-on-0g/agentic-id/overview
- ERC-7857 Standard: https://docs.0g.ai/developer-hub/building-on-0g/agentic-id/erc7857
- Integration Guide: https://docs.0g.ai/developer-hub/building-on-0g/agentic-id/integration
ERC-8004 Support: 0G officially supports ERC-8004 (Trustless Agents), the standard for on-chain agent identity, discoverability, and reputation. 0G's ERC-8004 registry deployment is listed in the official standard repo (erc-8004/erc-8004-contracts). Agentic ID is ERC-8004 compatible — an Agentic ID can carry a corresponding ERC-8004 registration. Registered agents are discoverable at 8004scan.io.
Registry Addresses:
- 0G Mainnet (chain ID 16661): IdentityRegistry
0x8004A169FB4a3325136EB29fA0ceB6D2e539a432, ReputationRegistry0x8004BAa17C55a88189AE136b182e5fdA19dE9b63(explorer: chainscan.0g.ai) - 0G Galileo Testnet (chain ID 16602): IdentityRegistry
0x8004A818BFB912233c491871b3d84c89A494BD9e, ReputationRegistry0x8004B663056A597Dffe9eCcC1965A193B7388713(explorer: chainscan-galileo.0g.ai)
ERC-8004 Guide: https://docs.0g.ai/developer-hub/building-on-0g/agentic-id/erc8004
Developer Tools
Indexing with Goldsky
Website: https://docs.goldsky.com/chains/0g
Products:
- Subgraphs: GraphQL indexing for smart contracts
- Mirror: Real-time data streaming to databases
Documentation: https://docs.0g.ai/developer-hub/building-on-0g/indexing/goldsky
Rollup-as-a-Service
Caldera on 0G DA: https://docs.0g.ai/developer-hub/building-on-0g/rollup-as-a-service/caldera-on-0g-da
Smart Contract Development
Deploy with Hardhat:
// hardhat.config.js
module.exports = {
networks: {
testnet: {
url: "https://evmrpc-testnet.0g.ai",
chainId: 16602,
accounts: ["YOUR_PRIVATE_KEY"]
},
mainnet: {
url: "https://evmrpc.0g.ai",
chainId: 16661,
accounts: ["YOUR_PRIVATE_KEY"]
}
}
};
Deploy with Foundry:
# Testnet
forge create --rpc-url https://evmrpc-testnet.0g.ai \
--private-key YOUR_PRIVATE_KEY \
src/MyContract.sol:MyContract
# Mainnet
forge create --rpc-url https://evmrpc.0g.ai \
--private-key YOUR_PRIVATE_KEY \
src/MyContract.sol:MyContract
Documentation: https://docs.0g.ai/developer-hub/building-on-0g/contracts-on-0g/deploy-contracts
Key Concepts
AI Alignment
Documentation: https://docs.0g.ai/concepts/ai-alignment
Monitor AI systems for proper behavior, safety, and alignment with human values.
Functions:
- Track model drift
- Verify outputs
- Monitor performance
- Flag anomalies
DePIN (Decentralized Physical Infrastructure)
Documentation: https://docs.0g.ai/concepts/depin
Physical GPU infrastructure provided by decentralized partners.
Partners:
- io.net: 300,000+ verified GPUs, 139 countries, 90% cost savings
- Aethir: 43,000+ enterprise GPUs, 3,000+ H100s/H200s, 99.99% uptime
Starter Kits & Examples
Compute Starter Kit
Quick Start (Recommended for Hackathons):
# Install global CLI
pnpm add @0gfoundation/0g-compute-ts-sdk -g
# Option 1: Web UI (fastest way to start)
0g-compute-cli ui start-web
# Open http://localhost:3090, connect wallet, start using AI
# Option 2: CLI for automation
0g-compute-cli setup-network # Choose testnet/mainnet
0g-compute-cli login # Connect your wallet
0g-compute-cli deposit --amount 10 # Fund account
0g-compute-cli inference list-providers # See available services
OpenAI SDK Drop-in Replacement:
from openai import OpenAI
# Just change base_url and api_key!
client = OpenAI(
api_key="app-sk-<YOUR_SECRET>",
base_url="<PROVIDER_URL>/v1/proxy"
)
# Same API as OpenAI
response = client.chat.completions.create(
model="<model_name>",
messages=[{"role": "user", "content": "Hello!"}]
)
Storage Starter Kit
TypeScript Example:
npm install @0gfoundation/0g-storage-ts-sdk ethers
import { ZgFile, Indexer } from "@0gfoundation/0g-storage-ts-sdk";
import { ethers } from "ethers";
const provider = new ethers.JsonRpcProvider("https://evmrpc-testnet.0g.ai");
const signer = new ethers.Wallet("YOUR_PRIVATE_KEY", provider);
const indexer = new Indexer("https://indexer-storage-testnet-turbo.0g.ai");
// Upload file — flow contract handled internally by Indexer
const file = await ZgFile.fromFilePath("/path/to/file");
const [tree, treeErr] = await file.merkleTree();
console.log("Root Hash:", tree?.rootHash());
const [tx, uploadErr] = await indexer.upload(file, "https://evmrpc-testnet.0g.ai", signer);
await file.close();
// Download file (withProof=true enables merkle verification)
const err = await indexer.download(rootHash, "/path/to/output", true);
Go Example:
go get github.com/0gfoundation/0g-storage-client
import (
"github.com/0gfoundation/0g-storage-client/common/blockchain"
"github.com/0gfoundation/0g-storage-client/indexer"
"github.com/0gfoundation/0g-storage-client/transfer"
"github.com/0gfoundation/0g-storage-client/core"
)
// Initialize clients
w3client := blockchain.MustNewWeb3(evmRpc, privateKey)
defer w3client.Close()
indexerClient, _ := indexer.NewClient(indexerRpc, indexer.IndexerClientOption{})
// Upload — flow contract handled internally by indexer
file, _ := core.Open(filePath)
defer file.Close()
opt := transfer.UploadOption{ExpectedReplica: 1, FastMode: true}
txHashes, roots, _ := indexerClient.SplitableUpload(ctx, w3client, file, 4*1024*1024*1024, opt)
// Download
indexerClient.Download(ctx, rootHash, outputPath, true)
Chain/Smart Contract Starter Kit
Hardhat Project:
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
npx hardhat init
// hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
module.exports = {
solidity: "0.8.20",
networks: {
testnet: {
url: "https://evmrpc-testnet.0g.ai",
chainId: 16602,
accounts: [process.env.PRIVATE_KEY]
}
}
};
npx hardhat compile
npx hardhat run scripts/deploy.js --network testnet
Foundry Project:
forge init my-project
cd my-project
# Deploy
forge create --rpc-url https://evmrpc-testnet.0g.ai \
--private-key $PRIVATE_KEY \
src/Counter.sol:Counter
# Verify interaction
cast call <CONTRACT_ADDRESS> "number()" --rpc-url https://evmrpc-testnet.0g.ai
SDK Examples
- TypeScript SDK: https://github.com/0gfoundation/0g-storage-ts-sdk/tree/main/examples
- Go SDK: https://github.com/0gfoundation/0g-storage-client/tree/main/examples
Community Projects
Awesome 0G Repository: https://github.com/0gfoundation/awesome-0g
Curated list of community projects, tools, and resources built on 0G.
Quick Reference
Add Network to MetaMask
Testnet:
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x40DA',
chainName: '0G Galileo Testnet',
nativeCurrency: { name: '0G', symbol: '0G', decimals: 18 },
rpcUrls: ['https://evmrpc-testnet.0g.ai'],
blockExplorerUrls: ['https://chainscan-galileo.0g.ai']
}]
});
Mainnet:
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x4115',
chainName: '0G Mainnet',
nativeCurrency: { name: '0G', symbol: '0G', decimals: 18 },
rpcUrls: ['https://evmrpc.0g.ai'],
blockExplorerUrls: ['https://chainscan.0g.ai']
}]
});
Common Commands
Storage Upload (CLI):
0g-storage-client upload \
--url https://evmrpc-testnet.0g.ai \
--key YOUR_PRIVATE_KEY \
--indexer https://indexer-storage-testnet-turbo.0g.ai \
--file /path/to/file
Storage Download (CLI):
0g-storage-client download \
--indexer https://indexer-storage-testnet-turbo.0g.ai \
--root ROOT_HASH \
--file output.dat
Community & Support
Official Links
- Documentation: https://docs.0g.ai
- Website: https://0g.ai
- GitHub: https://github.com/0gfoundation
- Discord: https://discord.gg/0gLabs
- Twitter/X: https://x.com/0g_Labs
Getting Help
- Documentation: https://docs.0g.ai/developer-hub/getting-started
- Discord Developer Channel: https://discord.gg/0gLabs
- GitHub Issues: Create issues in respective repositories
Vision & Mission
Mission: Make AI a Public Good
Vision: Democratized, transparent, fair, and secure AI infrastructure
Approach:
- Open infrastructure
- Community ownership
- Economic alignment
- Technical excellence
Documentation: https://docs.0g.ai/introduction/vision-mission
Additional Resources
Security
Documentation: https://docs.0g.ai/resources/security
Contributing
Documentation: https://docs.0g.ai/resources/how-to-contribute
Glossary
Documentation: https://docs.0g.ai/resources/glossary
Last verified: 2026-09-02 (see the ai-context-review workflow for automated drift checks). This context page gives AI coding assistants comprehensive information about 0G infrastructure. All information is sourced from official documentation at https://docs.0g.ai.