TypeScript SDK

The @puraxyz/sdk package provides a TypeScript client for interacting with all 32 Pura smart contracts.

Installation

shell
npm install @puraxyz/sdk

Features

Usage

typescript
import { addresses, contracts } from '@puraxyz/sdk'

// Get contract addresses for Base Sepolia
const { capacityRegistry, backpressurePool, stakeManager } = addresses.baseSepolia

// Use with viem
import { createPublicClient, http } from 'viem'
import { baseSepolia } from 'viem/chains'

const client = createPublicClient({
  chain: baseSepolia,
  transport: http(),
})

// Read smoothed capacity for a sink
const capacity = await client.readContract({
  ...contracts.capacityRegistry,
  functionName: 'getSmoothedCapacity',
  args: [taskTypeId, sinkAddress],
})

Action Modules

Core BPE

ModuleDescription
actions/sinkRegister/deregister sinks
actions/sourceRegister task types, start/stop payment streams
actions/poolCreate pools, rebalance, read member units
actions/stakeStake/unstake tokens, read capacity cap
actions/bufferDeposit to / drain from escrow buffer
actions/pricingReport queue load, advance pricing epoch, read prices
actions/completionRecord completions, advance completion epoch
actions/aggregatorSubmit batched off-chain attestations
signingEIP-712 signing helpers

Domain Extensions

ModuleDescription
actions/demurrageWrap/unwrap demurrage tokens, rebase, read decay rates
actions/relayRegister Nostr relays, join pools, set anti-spam minimums
actions/lightningRegister Lightning nodes, join routing pools, get optimal routes
actions/platformAggregate reputation, stake discounts, route attestations

V2 Economy

ModuleDescription
actions/economyDeploy economies via EconomyFactory, query deployments
actions/nestedPoolRegister child pools, hierarchical rebalance, effective capacity
actions/qualityReport latency/errors/satisfaction, compute quality scores
actions/velocityTokenWrap/unwrap with idle decay, stream exemption checks
actions/urgencyTokenTTL-stamped deposits, consume, burn, batch operations

Thermodynamic & Monitoring

ModuleDescription
actions/temperatureRead system temperature from capacity variance
actions/virialVirial ratio monitoring, capital equilibrium
actions/systemStateAggregate system snapshots (temperature, virial, pressure)
actions/verifyOn-chain verification helpers
actions/openclawOpenClaw agent registration and reputation

High-level client

The SDK also exports a high-level client with three convenience functions that wrap the lower-level action modules:

typescript
import { route, deploy, monitor } from '@puraxyz/sdk'

// Route an inference request through the gateway
const result = await route({ apiKey: 'pura_...', messages: [...] })

// Register as a provider (stake + register + connect to pool)
const txs = await deploy(wallet, addresses, { taskTypeId, initialCapacity: 100n, stakeAmount: 400n * 10n ** 18n })

// Read live protocol state
const state = await monitor(client, addresses)

Source

SDK source code is on GitHub.


See also