Skip to main content
The NEXUS SDK provides comprehensive tools for interacting with the NEXUS protocol. Available in both TypeScript and Rust, the SDK offers:
  • Wallet Management - Create, import, and manage Bitcoin-compatible wallets
  • Contract Deployment - Deploy WASM smart contracts
  • Contract Interaction - Call contract functions and query state
  • Vault Operations - Manage deposits and withdrawals
  • Event Subscriptions - Real-time event monitoring
  • Challenge System - BitVM2 fraud proof interactions

Installation

npm install @nexus/sdk
Requirements:
  • Node.js 18+
  • TypeScript 5.0+ (recommended)

Quick Example

import { NexusClient, Wallet } from '@nexus/sdk';

// Create wallet
const wallet = new Wallet(undefined, 'regtest');

// Initialize client
const client = new NexusClient({
  rpcUrl: 'http://localhost:8545',
  network: 'regtest',
}, wallet);

// Get balance
const balance = await client.getBalance();
console.log('Balance:', balance);

// Deploy contract
const wasm = await fs.readFile('./contract.wasm');
const { contractId } = await client.deployContract(wasm);

// Call contract
const result = await client.callContract(contractId, 'my_function', [arg1, arg2]);

SDK Components

Configuration Options

interface NexusConfig {
  // Primary RPC endpoint
  rpcUrl: string;
  
  // Fallback RPC endpoints for failover
  rpcUrls?: string[];
  
  // WebSocket URL for real-time events
  wsUrl?: string;
  
  // Network: 'mainnet' | 'testnet' | 'regtest'
  network?: string;
  
  // Request timeout in milliseconds
  timeout?: number;
  
  // Number of retry attempts
  retries?: number;
  
  // Rate limiting (requests per second)
  maxRequestsPerSecond?: number;
}

Error Handling

The SDK uses typed errors for better error handling:
try {
  await client.callContract(contractId, 'transfer', [to, amount]);
} catch (error) {
  if (error.code === 'INSUFFICIENT_BALANCE') {
    console.log('Not enough funds');
  } else if (error.code === 'INVALID_NONCE') {
    console.log('Nonce mismatch - retry');
  } else {
    throw error;
  }
}

Next Steps