🖥️CLI Guide

Complete guide for the Somnia Agent Kit command-line interface.

📦 Installation

Global Installation

# Install globally
npm install -g somnia-agent-kit

# Or with pnpm
pnpm add -g somnia-agent-kit

# Or with yarn
yarn global add somnia-agent-kit

Local Installation

# Install in your project
npm install somnia-agent-kit

# Use with npx
npx somnia-agent help

🚀 Quick Start

Initialize Configuration

Check Version

Get Help

Note: All commands support -h and --help flags for quick help access!

📋 Commands

🔧 Initialization

init - Initialize Configuration

Initialize CLI configuration with network settings and contract addresses.

Options:

  • -n, --network <network> - Network (testnet/mainnet/devnet) [default: testnet]

  • --rpc-url <url> - Custom RPC URL

  • -k, --private-key <key> - Private key

  • -i, --interactive - Interactive setup

Examples:

Configuration File:

The CLI stores configuration in ~/.somnia-agent/config.json:


🤖 Agent Management

agent:register - Register Agent

Register a new AI agent on-chain.

Options:

  • -n, --name <name> - Agent name (required)

  • -d, --description <desc> - Agent description

  • -m, --metadata <uri> - IPFS metadata URI

  • -c, --capabilities <list> - Comma-separated capabilities

  • --config <file> - Load from config file

Examples:

Config File Format:

Output:


agent:list - List Agents

List all registered agents.

Options:

  • -o, --owner <address> - Filter by owner address

  • -a, --active - Show only active agents

  • -l, --limit <n> - Limit results [default: 10]

  • -f, --format <type> - Output format (table/json) [default: table]

Examples:

Table Output:

JSON Output:


agent:info - Get Agent Info

Get detailed information about a specific agent.

Options:

  • -f, --format <type> - Output format (table/json) [default: table]

Examples:

Table Output:


⚡ Task Management

task:create - Create Task

Create a new task for an agent.

Options:

  • -d, --data <json> - Task data (JSON string)

  • -f, --file <path> - Load task data from file

  • -p, --payment <amount> - Payment amount in STT [default: 0]

Examples:

Task Data Format:

Output:


task:status - Get Task Status

Get the status and result of a task.

Options:

  • -f, --format <type> - Output format (table/json) [default: table]

Examples:

Table Output:


💰 Token Management

token:balance - Check Token Balance

Check ERC20 token or native STT balance.

Options:

  • -t, --token <address> - ERC20 token contract address (omit for native STT)

  • -f, --format <type> - Output format (table/json) [default: table]

Examples:

Output:


token:transfer - Transfer Tokens

Transfer ERC20 tokens or native STT.

Options:

  • -t, --token <address> - ERC20 token contract address (omit for native STT)

  • -d, --decimals <n> - Token decimals [default: 18]

Examples:

Output:


token:info - Get Token Information

Get detailed information about an ERC20 token.

Options:

  • -f, --format <type> - Output format (table/json) [default: table]

Examples:

Output:


token:approve - Approve Token Spending

Approve a spender to use your ERC20 tokens.

Options:

  • -d, --decimals <n> - Token decimals [default: 18]

Examples:

Output:


🎨 NFT Management

nft:owner - Get NFT Owner

Get the owner of a specific NFT.

Options:

  • -c, --collection <address> - NFT collection contract address (required)

  • -f, --format <type> - Output format (table/json) [default: table]

Examples:

Output:


nft:transfer - Transfer NFT

Transfer an NFT to another address.

Options:

  • -c, --collection <address> - NFT collection contract address (required)

Examples:

Output:


nft:metadata - Get NFT Metadata

Get metadata for an NFT.

Options:

  • -c, --collection <address> - NFT collection contract address (required)

  • -f, --format <type> - Output format (table/json) [default: table]

Examples:

Output:


🚀 Contract Deployment

deploy:contract - Deploy Smart Contract

Deploy a smart contract to Somnia network.

Options:

  • -b, --bytecode <path> - Path to bytecode file (required)

  • -a, --abi <path> - Path to ABI file (required)

  • --args <json> - Constructor arguments as JSON array

  • --gas-limit <n> - Gas limit for deployment

Examples:

Output:


deploy:create2 - Deploy with CREATE2

Deploy a contract using CREATE2 for deterministic addresses.

Options:

  • -b, --bytecode <path> - Path to bytecode file (required)

  • -a, --abi <path> - Path to ABI file (required)

  • -s, --salt <hex> - Salt for CREATE2 (32 bytes hex)

  • --args <json> - Constructor arguments as JSON array

Examples:

Output:


deploy:verify - Verify Contract

Verify a deployed contract on block explorer.

Options:

  • -b, --bytecode <path> - Path to bytecode file (required)

  • -a, --abi <path> - Path to ABI file

  • --args <json> - Constructor arguments as JSON array

  • --name <name> - Contract name

  • --compiler <version> - Solidity compiler version

Examples:

Output:


deploy:check - Check Verification Status

Check the verification status of a contract.

Examples:

Output:


⚡ Multicall

multicall:batch - Execute Batch Calls

Execute multiple contract calls in a single transaction using Multicall3.

Calls File Format (JSON):

Examples:

Output:


multicall:aggregate - Aggregate Multiple Calls

Aggregate multiple read-only calls without sending a transaction.

Examples:

Output:


📦 IPFS

ipfs:upload - Upload File to IPFS

Upload a file to IPFS.

Examples:

Output:


ipfs:get - Download from IPFS

Download a file from IPFS.

Examples:

Output:


ipfs:metadata - Upload NFT Metadata

Upload NFT metadata to IPFS.

Options:

  • -n, --name <name> - NFT name (required)

  • -d, --description <desc> - NFT description (required)

  • -i, --image <uri> - Image URI (IPFS or HTTP) (required)

  • -a, --attributes <json> - Attributes as JSON array

Examples:

Output:


💰 Wallet Commands

wallet:balance - Show Balance

Show wallet balance.

Examples:

Output:


wallet:info - Show Wallet Info

Show detailed wallet information.

Output:


🌐 Network Commands

network:info - Show Network Info

Show current network information.

Output:


network:contracts - Show Contract Addresses

Show deployed contract addresses.

Output:


🎯 Common Workflows

Complete Agent Lifecycle

Token & NFT Management

Contract Deployment Workflow

IPFS & NFT Metadata

Multicall for Batch Operations

Monitor Your Agents

Batch Operations


⚙️ Configuration

The CLI supports multiple configuration methods with the following priority (highest to lowest):

  1. Command-line arguments (highest priority)

  2. Environment variables

  3. .env file (automatic loading)

  4. Config file (~/.somnia-agent/config.json)

  5. Defaults (lowest priority)

The CLI automatically loads configuration from a .env file in your current directory!

Benefits:

  • ✅ No need to export variables every time

  • ✅ Works across terminal sessions

  • ✅ Easy to manage and version control (add to .gitignore!)

  • ✅ Industry best practice

.env.example Template:

Method 2: Environment Variables

Export variables in your shell:

Method 3: Config File

Initialize and use persistent config file:

Config File Format:

Method 4: Command-line Arguments

Override any config with CLI flags:

Configuration Priority Example


🐛 Troubleshooting

Configuration Not Found

Private Key Required

Insufficient Funds

Network Connection Issues


📊 Command Summary

The CLI provides 28 commands across 9 categories:

Category
Commands
Description

Initialization

init

Initialize configuration

Agent Management

agent:register, agent:list, agent:info

Manage AI agents

Task Management

task:create, task:status

Create and track tasks

Token Management

token:balance, token:transfer, token:info, token:approve

ERC20 & native tokens

NFT Management

nft:owner, nft:transfer, nft:metadata

ERC721 NFTs

Contract Deployment

deploy:contract, deploy:create2, deploy:verify, deploy:check

Deploy & verify contracts

Multicall

multicall:batch, multicall:aggregate

Batch RPC calls

IPFS

ipfs:upload, ipfs:get, ipfs:metadata

Decentralized storage

Wallet

wallet:balance, wallet:info

Wallet information

Network

network:info, network:contracts

Network details

Total: 28 commands - All support -h and --help flags!


💡 Tips & Best Practices

2. Use Short Alias

3. Get Help Anytime

4. JSON Output for Scripting

5. Save Common Commands as Aliases

6. Use Config Files for Complex Data

7. Combine with Other Tools

8. Batch Operations with Loops

9. Security Best Practices

10. Debug Mode


📚 See Also


🆘 Need Help?

  • Documentation: https://github.com/xuanbach0212/somnia-agent-kit

  • Issues: https://github.com/xuanbach0212/somnia-agent-kit/issues


Happy building with Somnia Agent Kit CLI! 🚀

Last updated