Skip to main content

0G AI Context for Coding Assistants

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

ParameterValue
Network Name0G-Galileo-Testnet
Chain ID16602
Token Symbol0G
RPC Endpointhttps://evmrpc-testnet.0g.ai (development only — use 3rd party RPCs for production)
Block Explorerhttps://chainscan-galileo.0g.ai
Storage Explorerhttps://storagescan-galileo.0g.ai
Validator Dashboardhttps://testnet.0g.explorers.guru
Faucethttps://faucet.0g.ai (0.1 0G/day)
Faucet (Google Cloud)https://cloud.google.com/application/web3/faucet/0g/galileo
Storage Indexerhttps://indexer-storage-testnet-turbo.0g.ai
Storage Start Block1
DA Start Block940000

Documentation: https://docs.0g.ai/developer-hub/testnet/testnet-overview

Third-Party RPCs (Recommended for Production):

Mainnet (Aristotle)

Explorer: https://explorer.0g.ai/mainnet/home

ParameterValue
Network Name0G Mainnet
Chain ID16661
Token Symbol0G
RPC Endpointhttps://evmrpc.0g.ai
Storage Indexerhttps://indexer-storage-turbo.0g.ai
Block Explorerhttps://chainscan.0g.ai
Storage Start Block2387557

Documentation: https://docs.0g.ai/developer-hub/mainnet/mainnet-overview

Third-Party RPCs (Recommended for Production):

Smart Contract Addresses

Testnet Contracts

ContractAddressPurpose
Flow0x22E03a6A89B950F1c82ec5e74F8eCa321a105296Storage data flow management
Mine0x00A9E9604b0538e06b268Fb297Df333337f9593bStorage mining rewards
Reward0xA97B57b4BdFEA2D0a25e535bd849ad4e6C440A69Reward distribution
DAEntrance0xE75A073dA5bb7b0eC622170Fd268f35E675a957BDA blob submission
DASigners0x0000000000000000000000000000000000001000DA signer management (precompile)
WrappedOGBase0x0000000000000000000000000000000000001001Wrapped native token (precompile)
Compute Ledger0xE70830508dAc0A97e6c087c75f402f9Be669E406Compute network payment ledger
Compute Inference0xa79F4c8311FF93C06b8CfB403690cc987c93F91ECompute inference service
Compute FineTuning0xaC66eBd174435c04F1449BBa08157a707B6fa7b1Compute fine-tuning service

Mainnet Contracts

ContractAddressPurpose
Flow0x62D4144dB0F0a6fBBaeb6296c785C71B3D57C526Storage data flow management
Mine0xCd01c5Cd953971CE4C2c9bFb95610236a7F414feStorage mining rewards
Reward0x457aC76B58ffcDc118AABD6DbC63ff9072880870Reward distribution
DASigners0x0000000000000000000000000000000000001000DA signer management (precompile)
WrappedOGBase0x0000000000000000000000000000000000001001Wrapped native token (precompile)
Compute Ledger0x2dE54c845Cd948B72D2e32e39586fe89607074E3Compute network payment ledger
Compute Inference0x47340d900bdFec2BD393c626E12ea0656F938d84Compute inference service
Compute FineTuning0x4e3474095518883744ddf135b7E0A23301c7F9c0Compute fine-tuning service

0G Services Overview

0G Chain

Documentation: https://docs.0g.ai/concepts/chain

Fastest modular AI 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:

  1. Open Remix IDE
  2. Compile your contract
  3. Go to Deploy & Run Transactions
  4. Select "Injected Provider - MetaMask"
  5. Ensure MetaMask is connected to 0G network
  6. Deploy!

Precompiled Contracts:

DASigners (0x0000000000000000000000000000000000001000):

// Query DA signers and epochs
function getEpochNumber(uint256 blockNumber) external view returns (uint256);
function getQuorum(uint256 epochNumber, uint256 quorumId) external view returns (Signer[] memory);
function isSigner(uint256 epochNumber, address account) external view returns (bool);

WrappedOGBase (0x0000000000000000000000000000000000001001):

// Wrapped native token (like WETH)
function deposit() external payable;
function withdraw(uint256 amount) external;
function balanceOf(address account) external view returns (uint256);

Verification & Indexing:

Documentation Links:

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-ts-sdk ethers

Go:

go get github.com/0gfoundation/0g-storage-client

Starter Kits (recommended for getting started quickly):

Quick Start Examples:

TypeScript - Upload File:

import { ZgFile, Indexer } from "@0gfoundation/0g-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-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)

Documentation Links:

GitHub Repositories:

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.003vs0.003 vs 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

Quick Start (5 minutes):

Install CLI:

pnpm add @0glabs/0g-serving-broker -g

Option 1 - Web UI (Easiest):

# Launch Web UI
0g-compute-cli ui start-web

# Open http://localhost:3090
# Connect wallet, deposit tokens, start using AI services

Option 2 - CLI:

# Setup network
0g-compute-cli setup-network

# Login with wallet
0g-compute-cli login

# Fund account
0g-compute-cli deposit --amount 10

# List available providers
0g-compute-cli inference list-providers

# Transfer funds to provider
0g-compute-cli transfer-fund --provider <PROVIDER_ADDRESS> --amount 5

# Acknowledge provider
0g-compute-cli inference acknowledge-provider --provider <PROVIDER_ADDRESS>

# Get API key for direct access
0g-compute-cli inference get-secret --provider <PROVIDER_ADDRESS>

Option 3 - Direct API (OpenAI Compatible):

curl <service_url>/v1/proxy/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer app-sk-<YOUR_SECRET>" \
-d '{
"model": "<model_name>",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'

OpenAI SDK Integration:

from openai import OpenAI

client = OpenAI(
api_key="app-sk-<YOUR_SECRET>",
base_url="<service_url>/v1/proxy"
)

response = client.chat.completions.create(
model="<model_name>",
messages=[
{"role": "user", "content": "Hello!"}
]
)

Fine-tuning Models:

# Prepare dataset (JSONL format)
# Each line: {"prompt": "...", "completion": "..."}

# Upload dataset
0g-compute-cli fine-tuning upload-data --file dataset.jsonl

# Create fine-tuning task
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:

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:

INFT (Intelligent NFTs)

Documentation: https://docs.0g.ai/concepts/inft

ERC-7857 is an 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.

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 of IntelligentData per 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:

  1. Receiver signs AccessProof (proving they want the data)
  2. TEE/ZKP oracle decrypts metadata, re-encrypts with receiver's public key, produces OwnershipProof with sealedKey
  3. iTransferFrom() calls verifier.verifyTransferValidity() to validate both proofs
  4. Token ownership transfers and PublishedSealedKey event emits for receiver to decrypt

Use Cases: AI Trading Bots, Personal Assistants, Game Characters, Content Creation AI, Research Tools

Documentation Links:

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 @0glabs/0g-serving-broker -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-ts-sdk ethers
import { ZgFile, Indexer } from "@0gfoundation/0g-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

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: '0x40EA',
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: '0x4125',
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

Getting Help

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


This context page is automatically maintained to provide AI coding assistants with comprehensive, up-to-date information about 0G infrastructure. All information is sourced from official documentation at https://docs.0g.ai.