Account
The 0G Compute Network uses a unified account system for managing funds across services. This guide covers how to manage your accounts using different interfaces: Web UI, CLI, and SDK.
Overview
The account system provides a secure and flexible way to manage funds across different AI service providers.
Account Structure
- Main Account: Your primary wallet where funds are deposited. All deposits go here first, and you can withdraw funds from here back to your wallet.
- Sub-Accounts: Provider-specific accounts created automatically when you transfer funds to a provider. Each provider has a separate sub-account where funds are locked for their specific services.
Fund Flow
- Deposit: Transfer funds from your wallet to your Main Account
- Transfer: Move funds from Main Account to Provider Sub-Accounts
- Usage: Provider deducts from Sub-Account for services rendered
- Refund Request: Initiate refund from Sub-Account (enters 24-hour lock period)
- Complete Refund: After lock period expires, call retrieve-fund again to complete transfer back to Main Account
- Withdraw: Transfer funds from Main Account back to your wallet
Security Features
- 24-hour lock period for refunds to protect providers from abuse
- Single-use authentication for each request to prevent replay attacks
- On-chain verification for all transactions ensuring transparency
- Provider acknowledgment required before first use of services
Prerequisites
- Node.js >= 22.0.0
- A wallet with 0G tokens (for testnet or mainnet)
- MetaMask or compatible wallet (for Web UI)
Web UI
The easiest way to manage your accounts is through the Web UI.
Getting Started with Web UI
pnpm add @0glabs/0g-serving-broker -g
# Launch the Web UI
0g-compute-cli ui start-web
Access the Web UI at http://localhost:3090/wallet where you can:
- View your account balance in real-time
- Deposit funds directly from your connected wallet
- Transfer funds to provider sub-accounts
- Monitor spending and usage
- Request refunds with a visual interface
CLI
The CLI provides command-line tools for account management, ideal for automation and scripting.
Setup
# Install the CLI tool globally
pnpm add @0glabs/0g-serving-broker -g
Setup Environment
Choose Network
0g-compute-cli setup-network
Login with Wallet
Enter your wallet private key when prompted. This will be used for account management and service payments.
0g-compute-cli login
CLI Commands
Deposit Funds
Add funds to your main account:
0g-compute-cli deposit --amount 10
Check Balance
View your account overview:
0g-compute-cli get-account
Example output:
Overview
┌──────────────────────────────────────────────────┬──────────────────────────────────── ─────────────────┐
│ Balance │ Value (0G) │
├──────────────────────────────────────────────────┼─────────────────────────────────────────────────────┤
│ Total │ 8.822778129999999663 │
├──────────────────────────────────────────────────┼─────────────────────────────────────────────────────┤
│ Locked (transferred to sub-accounts) │ 8.257334240000000491 │
├──────────────────────────────────────────────────┼─────────────────────────────────────────────────────┤
│ Available for transfer to sub-accounts │ 0.265443889999999960 │
└──────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘
Inference sub-accounts
┌────────────────────────┬──────────────────────────────┬────────────────────────────────────────────────┐
│ Provider │ Balance (0G) │ Requested Return to Main Account (0G) │
├────────────────────────┼──────────────────────────────┼────────────────────────────────────────────────┤
│ 0x924A2c71... │ 3.257334240000000047 │ 0.000000000000000000 │
├────────────────────────┼──────────────────────────────┼────────────────────────────────────────────────┤
│ 0x960E74Fc... │ 3.000000000000000000 │ 3.000000000000000000 │
├────────────────────────┼──────────────────────────────┼────────────────────────────────────────────────┤
│ 0x4f371f6e... │ 3.299999999999999822 │ 0.000000000000000000 │
└────────────────────────┴──────────────────────────────┴────────────────────────────────────────────────┘
Transfer to Provider
Before using a provider's service, transfer funds to their sub-account:
0g-compute-cli transfer-fund --provider <PROVIDER_ADDRESS> --amount 5
Request Refund
Withdraw unused funds from sub-accounts back to main account:
0g-compute-cli retrieve-fund
Note: Refunds have a 24-hour lock period for security. After the lock period expires, you need to call this function again to complete the refund and transfer the funds back to your main account. You can check the remaining lock time using the get-sub-account command:
0g-compute-cli get-sub-account --provider <PROVIDER_ADDRESS>
Example output showing refund details:
Details of Each Amount Applied for Return to Main Account
┌──────────────────────────────────────────────────┬──────────────────────────────────────────────────┐
│ Amount (0G) │ Remaining Locked Time │
├──────────────────────────────────────────────────┼──────────────────────────────────────────────────┤
│ 0.099785050000000000 │ 23h 43min 15s │
└──────────────────────────────────────────────────┴───────────────────── ─────────────────────────────┘
Withdraw to Wallet
Withdraw funds from main account to your wallet:
0g-compute-cli refund --amount 5
SDK
For programmatic account management in your applications.
Installation
pnpm add @0glabs/0g-serving-broker