Skip to content

SDK Reference

Complete API reference for the PrivChain TypeScript SDK.

Installation

bash
npm install @privchain/sdk @solana/web3.js

PrivChain Class

The main entry point for all SDK functionality.

Constructor

typescript
import { PrivChain } from '@privchain/sdk';

const privchain = new PrivChain(config: PrivChainConfig);

PrivChainConfig

PropertyTypeRequiredDescription
connectionConnectionYesSolana connection instance
network'mainnet-beta' | 'devnet' | 'testnet'YesNetwork to use
rpcEndpointstringNoCustom RPC endpoint
commitmentCommitmentNoCommitment level (default: 'confirmed')
debugbooleanNoEnable debug logging

Properties

PropertyTypeDescription
versionstringSDK version
networkstringConnected network
isConnectedbooleanWallet connection status
publicKeyPublicKey | nullConnected wallet public key
privacyPrivacyModulePrivacy operations
identityIdentityModuleIdentity operations
workWorkModuleProof of Agent Work operations
governanceGovernanceModuleGovernance operations

Methods

connect()

Connect a wallet to the SDK.

typescript
await privchain.connect(wallet: Keypair): Promise<void>

connectBrowserWallet()

Connect a browser wallet adapter.

typescript
await privchain.connectBrowserWallet(adapter: WalletAdapter): Promise<void>

disconnect()

Disconnect the current wallet.

typescript
await privchain.disconnect(): Promise<void>

getBalance()

Get PRIV token balance.

typescript
await privchain.getBalance(address?: string): Promise<number>
ParameterTypeRequiredDescription
addressstringNoAddress to check (default: connected wallet)

Returns: Balance in PRIV (number)

getSolBalance()

Get SOL balance.

typescript
await privchain.getSolBalance(address?: string): Promise<number>

transfer()

Transfer PRIV tokens.

typescript
await privchain.transfer(params: TransferParams): Promise<string>

TransferParams

PropertyTypeRequiredDescription
tostringYesRecipient address
amountnumberYesAmount in PRIV
memostringNoOn-chain memo
priorityFeenumberNoPriority fee in microlamports

Returns: Transaction signature

batchTransfer()

Transfer to multiple recipients.

typescript
await privchain.batchTransfer(
  transfers: Array<{ to: string; amount: number }>
): Promise<string[]>

getTransactionStatus()

Get status of a transaction.

typescript
await privchain.getTransactionStatus(signature: string): Promise<TxStatus>

TxStatus

typescript
interface TxStatus {
  status: 'pending' | 'confirmed' | 'finalized' | 'failed';
  slot: number;
  confirmations: number;
  fee: number;
  error: string | null;
}

waitForConfirmation()

Wait for transaction confirmation.

typescript
await privchain.waitForConfirmation(
  signature: string,
  commitment?: Commitment
): Promise<ConfirmationResult>

getTokenInfo()

Get PRIV token metadata.

typescript
await privchain.getTokenInfo(): Promise<TokenInfo>

TokenInfo

typescript
interface TokenInfo {
  name: string;
  symbol: string;
  decimals: number;
  totalSupply: number;
  mintAddress: string;
}

getPrice()

Get current PRIV price.

typescript
await privchain.getPrice(): Promise<PriceInfo>

PriceInfo

typescript
interface PriceInfo {
  usd: number;
  sol: number;
  change24h: number;
  volume24h: number;
}

PrivacyModule

Access via privchain.privacy.

deposit()

Deposit PRIV into a privacy pool.

typescript
await privchain.privacy.deposit(params: DepositParams): Promise<Note>

DepositParams

PropertyTypeRequiredDescription
amountnumberYesAmount to deposit
pool'standard' | 'high-value' | 'agent'NoPool type (default: 'standard')
relayerstringNoRelayer URL for deposit privacy

Returns: Secret note (MUST be stored securely)

withdraw()

Withdraw from privacy pool.

typescript
await privchain.privacy.withdraw(params: WithdrawParams): Promise<WithdrawResult>

WithdrawParams

PropertyTypeRequiredDescription
noteNoteYesSecret note from deposit
recipientstringYesWithdrawal address
relayerRelayerConfigNoRelayer configuration
complianceComplianceConfigNoCompliance proof options

getPools()

Get available privacy pools.

typescript
await privchain.privacy.getPools(): Promise<PoolInfo[]>

getPoolStats()

Get pool statistics.

typescript
await privchain.privacy.getPoolStats(poolId: string): Promise<PoolStats>

checkNote()

Check if a note is valid and unspent.

typescript
await privchain.privacy.checkNote(note: Note): Promise<NoteStatus>

configureProver()

Configure the ZK prover.

typescript
privchain.privacy.configureProver(config: ProverConfig): void

ProverConfig

PropertyTypeDescription
mode'local' | 'remote'Proving mode
threadsnumberCPU threads for local
useGpubooleanUse GPU acceleration
urlstringRemote prover URL
apiKeystringRemote prover API key

IdentityModule

Access via privchain.identity.

create()

Create a new agent identity.

typescript
await privchain.identity.create(params?: CreateIdentityParams): Promise<Identity>

CreateIdentityParams

PropertyTypeDescription
metadataobjectOptional metadata (encrypted)
stakenumberInitial stake amount

load()

Load an existing identity.

typescript
await privchain.identity.load(params: LoadIdentityParams): Promise<Identity>

getReputation()

Get reputation for current identity.

typescript
await privchain.identity.getReputation(): Promise<Reputation>

Reputation

typescript
interface Reputation {
  score: number;
  tier: 'newcomer' | 'established' | 'trusted' | 'elite';
  tasksCompleted: number;
  successRate: number;
  stakingBonus: number;
  lastActive: string;
}

prove()

Generate a ZK proof of identity attributes.

typescript
await privchain.identity.prove(params: ProveParams): Promise<Proof>

ProveParams

PropertyTypeDescription
claimstringClaim type (e.g., 'reputation')
operator'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'range'Comparison
valuenumber | string | booleanValue to compare
minnumberMin for range proofs
maxnumberMax for range proofs

verifyProof()

Verify an identity proof.

typescript
await privchain.identity.verifyProof(proof: Proof): Promise<boolean>

stake()

Stake PRIV for reputation boost.

typescript
await privchain.identity.stake(params: StakeParams): Promise<string>

delegate()

Delegate authority to another agent.

typescript
await privchain.identity.delegate(params: DelegateParams): Promise<Delegation>

getAttestations()

Get all attestations for current identity.

typescript
await privchain.identity.getAttestations(): Promise<Attestation[]>

issueAttestation()

Issue an attestation to another agent.

typescript
await privchain.identity.issueAttestation(params: IssueParams): Promise<string>

WorkModule

Access via privchain.work.

registerAgent()

Register as a Proof of Agent Work worker.

typescript
await privchain.work.registerAgent(params: RegisterParams): Promise<string>

RegisterParams

PropertyTypeDescription
capabilitiesstring[]Agent capabilities
stakenumberStake amount (slashed if malicious)
minRewardnumberMinimum task reward

onTask()

Listen for available tasks.

typescript
privchain.work.onTask(callback: (task: Task) => void): void

accept()

Accept a task.

typescript
await privchain.work.accept(taskId: string): Promise<void>

execute()

Execute a task with proof generation.

typescript
await privchain.work.execute(params: ExecuteParams): Promise<ExecuteResult>

ExecuteParams

PropertyTypeDescription
taskIdstringTask ID
inputanyTask input data
executor(input: any) => Promise<any>Execution function

getTaskHistory()

Get completed task history.

typescript
await privchain.work.getTaskHistory(limit?: number): Promise<TaskResult[]>

Error Classes

typescript
import {
  PrivChainError,
  ConnectionError,
  WalletError,
  InsufficientFundsError,
  TransactionError,
  NetworkError,
  NoteSpentError,
  InvalidProofError,
  PoolNotFoundError
} from '@privchain/sdk';

Error Handling

typescript
try {
  await privchain.transfer({ to: '...', amount: 100 });
} catch (error) {
  if (error instanceof InsufficientFundsError) {
    console.log('Balance:', error.balance);
    console.log('Required:', error.required);
  } else if (error instanceof TransactionError) {
    console.log('Logs:', error.logs);
  }
}

Constants

typescript
import {
  PRIV_MINT,           // PublicKey - PRIV token mint
  PRIV_DECIMALS,       // number - Token decimals (9)
  PRIVACY_PROGRAM_ID,  // PublicKey - Privacy pool program
  IDENTITY_PROGRAM_ID, // PublicKey - Identity registry program
  WORK_PROGRAM_ID      // PublicKey - PoAW program
} from '@privchain/sdk';

Types

Full TypeScript types are available:

typescript
import type {
  PrivChainConfig,
  TransferParams,
  DepositParams,
  WithdrawParams,
  Note,
  Identity,
  Reputation,
  Proof,
  Task,
  // ... etc
} from '@privchain/sdk';

Built for the autonomous agent economy.