Skip to content

SDK Reference

The @slabond/sdk package provides a TypeScript client for interacting with the Slabond Protocol.

Installation

bash
npm install @slabond/sdk

Constructor

typescript
import { Slabond } from '@slabond/sdk'

const slabond = new Slabond(config: SlabondConfig)

SlabondConfig

typescript
interface SlabondConfig {
  /** API key for authenticating with the Slabond watcher network */
  apiKey: string

  /** Base URL of the Slabond API (default: https://api.slabond.xyz) */
  baseUrl?: string

  /** Request timeout in milliseconds (default: 30000) */
  timeout?: number
}

Example:

typescript
const slabond = new Slabond({
  apiKey: process.env.SLABOND_API_KEY,
  baseUrl: 'https://api.slabond.xyz',
  timeout: 60000,
})

Methods

createSLA

Creates a new SLA and deposits escrow on-chain.

typescript
const sla = await slabond.createSLA(params: CreateSLAParams): Promise<SLAJob>

CreateSLAParams

typescript
interface CreateSLAParams {
  /** Unique identifier for this SLA */
  slaId: string

  /** Ethereum address of the requester */
  requester: string

  /** Escrow amount with denomination (e.g., '1000.00 USDC') */
  amount: string

  /** Target API endpoint to execute */
  targetUrl: string

  /** HTTP method (default: 'POST') */
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE'

  /** Request headers */
  headers?: Record<string, string>

  /** Request body (for POST/PUT) */
  body?: string | Record<string, unknown>

  /** Expected response pattern for proof verification */
  expectedResponse?: string

  /** Bond tier: 'instant' (200% bond, 50bps fee) or 'standard' (50% bond, 10bps fee) */
  bondTier?: 'instant' | 'standard'

  /** SLA timeout in seconds (default: 3600) */
  timeout?: number
}

Example:

typescript
const sla = await slabond.createSLA({
  slaId: 'payment-001',
  requester: '0xYourWallet',
  amount: '1000.00 USDC',
  targetUrl: 'https://api.stripe.com/v1/charges',
  method: 'POST',
  body: { amount: 100000, currency: 'usd' },
  bondTier: 'instant',
  timeout: 1800,
})

getSLA

Retrieves the current state of an SLA by ID.

typescript
const sla = await slabond.getSLA(id: string): Promise<SLAJob>

Example:

typescript
const sla = await slabond.getSLA('payment-001')
console.log(sla.status) // 'BOND_LOCKED'
console.log(sla.operator) // '0xOperatorAddress'

listSLAs

Lists all SLAs for the authenticated user.

typescript
const slas = await slabond.listSLAs(): Promise<SLAJob[]>

Example:

typescript
const slas = await slabond.listSLAs()
for (const sla of slas) {
  console.log(`${sla.slaId}: ${sla.status}`)
}

waitForSettlement

Polls an SLA until it reaches a terminal state (SETTLED, SLASHED, CANCELLED, or EXPIRED).

typescript
const result = await slabond.waitForSettlement(
  id: string,
  options?: WaitOptions
): Promise<SLAJob>

WaitOptions

typescript
interface WaitOptions {
  /** Polling interval in milliseconds (default: 5000) */
  pollInterval?: number

  /** Maximum time to wait in milliseconds (default: 3600000) */
  maxWait?: number
}

Example:

typescript
const result = await slabond.waitForSettlement('payment-001', {
  pollInterval: 10000,
  maxWait: 7200000,
})

if (result.status === 'SETTLED') {
  console.log('Payment confirmed:', result.proof)
} else if (result.status === 'SLASHED') {
  console.log('Operator slashed, bond distributed')
}

getStats

Returns aggregate statistics for the watcher network.

typescript
const stats = await slabond.getStats(): Promise<WatcherStats>

Example:

typescript
const stats = await slabond.getStats()
console.log(`Active operators: ${stats.activeOperators}`)
console.log(`Total SLAs processed: ${stats.totalSLAs}`)
console.log(`Success rate: ${stats.successRate}%`)

ping

Health check for the Slabond API.

typescript
const ok = await slabond.ping(): Promise<boolean>

Example:

typescript
const ok = await slabond.ping()
if (!ok) {
  throw new Error('Slabond API is unreachable')
}

Types

SLAJob

typescript
interface SLAJob {
  /** Unique SLA identifier */
  slaId: string

  /** Internal job ID */
  id: string

  /** Current status */
  status: JobStatus

  /** Requester's Ethereum address */
  requester: string

  /** Escrow amount */
  amount: string

  /** Target API endpoint */
  targetUrl: string

  /** Assigned operator address (null if pending) */
  operator: string | null

  /** Bond amount locked by operator */
  bondAmount: string | null

  /** TLSNotary proof (available after ProofSubmitted) */
  proof: string | null

  /** On-chain transaction hash for settlement */
  settlementTx: string | null

  /** ISO 8601 creation timestamp */
  createdAt: string

  /** ISO 8601 last update timestamp */
  updatedAt: string
}

JobStatus

typescript
enum JobStatus {
  CREATED = 'CREATED',
  BOND_LOCKED = 'BOND_LOCKED',
  PROOF_SUBMITTED = 'PROOF_SUBMITTED',
  SETTLED = 'SETTLED',
  CANCELLED = 'CANCELLED',
  EXPIRED = 'EXPIRED',
  CHALLENGED = 'CHALLENGED',
  SLASHED = 'SLASHED',
}

WatcherStats

typescript
interface WatcherStats {
  /** Number of currently active operators */
  activeOperators: number

  /** Total SLAs processed since genesis */
  totalSLAs: number

  /** Success rate as a percentage (0-100) */
  successRate: number

  /** Total value settled in USD */
  totalValueSettled: string

  /** Average settlement time in seconds */
  avgSettlementTime: number

  /** Current network uptime percentage */
  uptime: number
}

Secured by Intel SGX, TLSNotary & Ethereum