skills/chain/scaffold-project/SKILL.md
# Scaffold 0G Project ## Metadata - **Category**: chain - **SDK**: `ethers` ^6.13.0, `@0glabs/0g-ts-sdk` ^0.3.3, `@0glabs/0g-serving-broker` ^0.6.5 - **Activation Triggers**: "new project", "scaffold", "initialize", "create 0G app", "setup project" ## Purpose Initialize a new 0G dApp project with the correct SDK versions, TypeScript configuration, environment setup, and boilerplate code for storage, compute, and/or chain interactions. ## Prerequisites - Node.js >= 18 - npm or pnpm ## Quic
npx skillsauth add 0gfoundation/0g-agent-skills skills/chain/scaffold-projectInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
ethers ^6.13.0, @0glabs/0g-ts-sdk ^0.3.3, @0glabs/0g-serving-broker ^0.6.5Initialize a new 0G dApp project with the correct SDK versions, TypeScript configuration, environment setup, and boilerplate code for storage, compute, and/or chain interactions.
.env template and .gitignoreevmVersion: "cancun" for Hardhat/Foundry configs.env with placeholder values (never real keys).env to .gitignoredotenv/config for environment variable loading.gitignore creation# Create and initialize project
mkdir my-0g-app && cd my-0g-app
npm init -y
# Install all 0G SDKs
npm install @0glabs/0g-ts-sdk @0glabs/0g-serving-broker ethers dotenv
# Install dev dependencies
npm install -D typescript tsx @types/node
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["src/**/*"]
}
# Network
RPC_URL=https://evmrpc-testnet.0g.ai
CHAIN_ID=16602
# Wallet (NEVER commit real keys)
PRIVATE_KEY=your_private_key_here
# Storage
STORAGE_INDEXER=https://indexer-storage-testnet-turbo.0g.ai
# Compute
PROVIDER_ADDRESS=your_provider_address
node_modules/
dist/
.env
.env.local
.env.*.local
*.log
{
"scripts": {
"build": "tsc",
"start": "tsx src/index.ts",
"dev": "tsx watch src/index.ts"
}
}
npm install @0glabs/0g-ts-sdk ethers dotenv
npm install -D typescript tsx @types/node
// src/index.ts
import { ZgFile, Indexer } from '@0glabs/0g-ts-sdk';
import { ethers } from 'ethers';
import 'dotenv/config';
async function main() {
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
const indexer = new Indexer(process.env.STORAGE_INDEXER!);
console.log('0G Storage client initialized');
console.log('Wallet:', wallet.address);
}
main().catch(console.error);
npm install @0glabs/0g-serving-broker ethers dotenv
npm install -D typescript tsx @types/node
// src/index.ts
import { ethers } from 'ethers';
import { createZGComputeNetworkBroker } from '@0glabs/0g-serving-broker';
import 'dotenv/config';
async function main() {
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
const broker = await createZGComputeNetworkBroker(wallet);
console.log('0G Compute broker initialized');
const services = await broker.inference.listService();
console.log(`Available services: ${services.length}`);
}
main().catch(console.error);
mkdir my-0g-contracts && cd my-0g-contracts
npm init -y
npm install -D hardhat @nomicfoundation/hardhat-toolbox dotenv typescript tsx
npx hardhat init # Choose TypeScript project
// hardhat.config.ts
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
import 'dotenv/config';
const config: HardhatUserConfig = {
solidity: {
version: '0.8.24',
settings: {
optimizer: { enabled: true, runs: 200 },
evmVersion: 'cancun', // REQUIRED for 0G Chain
},
},
networks: {
'0g-testnet': {
url: 'https://evmrpc-testnet.0g.ai',
chainId: 16602,
accounts: [process.env.PRIVATE_KEY!],
},
'0g-mainnet': {
url: 'https://evmrpc.0g.ai',
chainId: 16661,
accounts: [process.env.PRIVATE_KEY!],
},
},
};
export default config;
| Project Type | Dependencies | Use Case |
| --------------- | ------------------------------------- | --------------- |
| Full-Stack | All 3 SDKs | Complete dApp |
| Storage Only | @0glabs/0g-ts-sdk, ethers | File/KV storage |
| Compute Only | @0glabs/0g-serving-broker, ethers | AI inference |
| Smart Contracts | hardhat, toolbox, ethers | On-chain logic |
# BAD: Installing ethers v5
npm install ethers@5 # WRONG — use v6
# BAD: Missing evmVersion in Hardhat config
# solidity: { version: "0.8.24" } # Missing evmVersion: "cancun"
// BAD: Hardcoded credentials in boilerplate
const wallet = new ethers.Wallet('0xabc...', provider);
// BAD: ethers v5 pattern
import { providers } from 'ethers'; // v5 pattern!
| Error | Cause | Fix |
| ------------------------ | -------------------------- | ------------------------------ |
| Cannot find module | Dependencies not installed | Run npm install |
| invalid opcode | Wrong evmVersion | Set evmVersion: "cancun" |
| PRIVATE_KEY not set | Missing .env file | Create .env with credentials |
| ethers v5 import error | Wrong ethers version | npm install ethers@^6.13.0 |
development
# Upload File to 0G Storage ## Metadata - **Category**: storage - **SDK**: `@0glabs/0g-ts-sdk` ^0.3.3, `ethers` ^6.13.0 - **Activation Triggers**: "upload file", "store on 0G", "ZgFile", "save to storage" ## Purpose Upload files to 0G decentralized storage using the ZgFile API and Indexer. Files are split into chunks, organized as a Merkle tree, and distributed across storage nodes. Returns a root hash for later retrieval. ## Prerequisites - Node.js >= 18 - `@0glabs/0g-ts-sdk` and `ethers`
development
# Merkle Verification ## Metadata - **Category**: storage - **SDK**: `@0glabs/0g-ts-sdk` ^0.3.3 - **Activation Triggers**: "verify file", "merkle proof", "data integrity", "root hash", "check file" ## Purpose Compute root hashes and verify data integrity for files stored on 0G Storage. Uses Merkle tree proofs to cryptographically verify that downloaded data matches what was originally uploaded. ## Prerequisites - Node.js >= 18 - `@0glabs/0g-ts-sdk` installed ## Quick Workflow 1. Create
development
# 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-sdk` installed - Root hash of the file to download - `
development
# Storage + Chain Integration ## Metadata - **Category**: cross-layer - **SDK**: `@0glabs/0g-ts-sdk` ^0.3.3, `ethers` ^6.13.0 - **Activation Triggers**: "on-chain reference", "NFT metadata on 0G", "store hash on-chain", "registry contract", "chain and storage" ## Purpose Combine 0G Storage with 0G Chain smart contracts to create on-chain references to off-chain data. Common patterns include NFT metadata storage, content registries, and verifiable document systems. ## Prerequisites - Node