Getting Started

Learn how to integrate Opacus Protocol into your application in minutes. This guide will walk you through installation, basic setup, and your first agent registration.

Prerequisites

Before you begin, make sure you have:

💡 Need Testnet Tokens?

Visit the 0G testnet faucet to get free tokens for development and testing.

Installation

TypeScript SDK

Install the Opacus TypeScript SDK using npm or yarn:

npm install @opacus/sdk
# or
yarn add @opacus/sdk
# or
pnpm add @opacus/sdk

Rust SDK

Add the Opacus Rust SDK to your Cargo.toml:

[dependencies]
opacus-rust = "0.1.0"
tokio = { version = "1.0", features = ["full"] }

Quick Start

TypeScript Example

Initialize the Opacus client and connect to 0G Chain:

import { OpacusClient } from '@opacus/sdk';

// Initialize client
const client = new OpacusClient({
  rpcUrl: 'https://evmrpc-testnet.0g.ai',
  contractAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
  privateKey: process.env.PRIVATE_KEY
});

// Connect to the network
await client.connect();

// Register a new AI agent
const agentId = await client.registerAgent({
  metadata: {
    name: 'MyAIAgent',
    version: '1.0.0',
    capabilities: ['text-generation', 'reasoning']
  }
});

console.log('Agent registered with ID:', agentId);

Rust Example

Create and register an agent using the Rust SDK:

use opacus_rust::{OpacusClient, AgentMetadata};

#[tokio::main]
async fn main() -> Result<(), Box> {
    // Initialize client
    let client = OpacusClient::new(
        "https://evmrpc-testnet.0g.ai",
        "0x5FbDB2315678afecb367f032d93F642f64180aa3",
        std::env::var("PRIVATE_KEY")?
    ).await?;
    
    // Register agent
    let metadata = AgentMetadata {
        name: "MyAIAgent".to_string(),
        version: "1.0.0".to_string(),
        capabilities: vec![
            "text-generation".to_string(),
            "reasoning".to_string()
        ],
    };
    
    let agent_id = client.register_agent(metadata).await?;
    println!("Agent registered with ID: {}", agent_id);
    
    Ok(())
}

✅ Success!

You've successfully registered your first AI agent on Opacus Protocol. The agent now has a unique, verifiable identity on the blockchain.

Next Steps

Common Tasks

Creating Attestations

Attestations allow agents to prove their capabilities without revealing sensitive information:

// Create an attestation
const attestation = await client.createAttestation({
  agentId: agentId,
  capability: 'text-generation',
  proof: proofData
});

// Verify an attestation
const isValid = await client.verifyAttestation(attestation);

Listening to Events

Subscribe to real-time events from the Opacus protocol:

// Listen for agent registrations
client.on('agentRegistered', (event) => {
  console.log('New agent:', event.agentId);
});

// Listen for attestation events
client.on('attestationCreated', (event) => {
  console.log('New attestation:', event.attestationId);
});

⚠️ Security Note

Never expose private keys in client-side code. Use environment variables and secure key management solutions in production.

Troubleshooting

Connection Issues

If you're having trouble connecting to the network:

Transaction Failures

Common reasons for transaction failures:

For more detailed troubleshooting, see our Troubleshooting Guide.

Getting Help

If you need assistance: