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:
- Node.js 18+ or Rust 1.70+
- A wallet with 0G testnet tokens
- Basic understanding of blockchain concepts
- An IDE or text editor of your choice
💡 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
Explore TypeScript SDK
Learn about advanced features like attestations, event listening, and real-time communication.
Explore Rust SDK
Discover high-performance patterns, QUIC transport, and async/await best practices.
Understand Architecture
Deep dive into the protocol's design, smart contracts, and cryptographic foundations.
Browse Examples
Explore real-world code examples and common integration patterns for various use cases.
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:
- Verify your RPC URL is correct
- Check that you have sufficient balance for gas fees
- Ensure your network connection is stable
- Try switching to a different RPC endpoint
Transaction Failures
Common reasons for transaction failures:
- Insufficient gas limit
- Invalid contract address
- Missing or invalid parameters
- Network congestion
For more detailed troubleshooting, see our Troubleshooting Guide.
Getting Help
If you need assistance:
- Join our Discord community
- Open an issue on GitHub
- Check the FAQ section
- Contact support at info@opacus.xyz