SDK Reference
Complete API reference for the PrivChain TypeScript SDK.
Installation
npm install @privchain/sdk @solana/web3.jsPrivChain Class
The main entry point for all SDK functionality.
Constructor
import { PrivChain } from '@privchain/sdk';
const privchain = new PrivChain(config: PrivChainConfig);PrivChainConfig
| Property | Type | Required | Description |
|---|---|---|---|
connection | Connection | Yes | Solana connection instance |
network | 'mainnet-beta' | 'devnet' | 'testnet' | Yes | Network to use |
rpcEndpoint | string | No | Custom RPC endpoint |
commitment | Commitment | No | Commitment level (default: 'confirmed') |
debug | boolean | No | Enable debug logging |
Properties
| Property | Type | Description |
|---|---|---|
version | string | SDK version |
network | string | Connected network |
isConnected | boolean | Wallet connection status |
publicKey | PublicKey | null | Connected wallet public key |
privacy | PrivacyModule | Privacy operations |
identity | IdentityModule | Identity operations |
work | WorkModule | Proof of Agent Work operations |
governance | GovernanceModule | Governance operations |
Methods
connect()
Connect a wallet to the SDK.
await privchain.connect(wallet: Keypair): Promise<void>connectBrowserWallet()
Connect a browser wallet adapter.
await privchain.connectBrowserWallet(adapter: WalletAdapter): Promise<void>disconnect()
Disconnect the current wallet.
await privchain.disconnect(): Promise<void>getBalance()
Get PRIV token balance.
await privchain.getBalance(address?: string): Promise<number>| Parameter | Type | Required | Description |
|---|---|---|---|
address | string | No | Address to check (default: connected wallet) |
Returns: Balance in PRIV (number)
getSolBalance()
Get SOL balance.
await privchain.getSolBalance(address?: string): Promise<number>transfer()
Transfer PRIV tokens.
await privchain.transfer(params: TransferParams): Promise<string>TransferParams
| Property | Type | Required | Description |
|---|---|---|---|
to | string | Yes | Recipient address |
amount | number | Yes | Amount in PRIV |
memo | string | No | On-chain memo |
priorityFee | number | No | Priority fee in microlamports |
Returns: Transaction signature
batchTransfer()
Transfer to multiple recipients.
await privchain.batchTransfer(
transfers: Array<{ to: string; amount: number }>
): Promise<string[]>getTransactionStatus()
Get status of a transaction.
await privchain.getTransactionStatus(signature: string): Promise<TxStatus>TxStatus
interface TxStatus {
status: 'pending' | 'confirmed' | 'finalized' | 'failed';
slot: number;
confirmations: number;
fee: number;
error: string | null;
}waitForConfirmation()
Wait for transaction confirmation.
await privchain.waitForConfirmation(
signature: string,
commitment?: Commitment
): Promise<ConfirmationResult>getTokenInfo()
Get PRIV token metadata.
await privchain.getTokenInfo(): Promise<TokenInfo>TokenInfo
interface TokenInfo {
name: string;
symbol: string;
decimals: number;
totalSupply: number;
mintAddress: string;
}getPrice()
Get current PRIV price.
await privchain.getPrice(): Promise<PriceInfo>PriceInfo
interface PriceInfo {
usd: number;
sol: number;
change24h: number;
volume24h: number;
}PrivacyModule
Access via privchain.privacy.
deposit()
Deposit PRIV into a privacy pool.
await privchain.privacy.deposit(params: DepositParams): Promise<Note>DepositParams
| Property | Type | Required | Description |
|---|---|---|---|
amount | number | Yes | Amount to deposit |
pool | 'standard' | 'high-value' | 'agent' | No | Pool type (default: 'standard') |
relayer | string | No | Relayer URL for deposit privacy |
Returns: Secret note (MUST be stored securely)
withdraw()
Withdraw from privacy pool.
await privchain.privacy.withdraw(params: WithdrawParams): Promise<WithdrawResult>WithdrawParams
| Property | Type | Required | Description |
|---|---|---|---|
note | Note | Yes | Secret note from deposit |
recipient | string | Yes | Withdrawal address |
relayer | RelayerConfig | No | Relayer configuration |
compliance | ComplianceConfig | No | Compliance proof options |
getPools()
Get available privacy pools.
await privchain.privacy.getPools(): Promise<PoolInfo[]>getPoolStats()
Get pool statistics.
await privchain.privacy.getPoolStats(poolId: string): Promise<PoolStats>checkNote()
Check if a note is valid and unspent.
await privchain.privacy.checkNote(note: Note): Promise<NoteStatus>configureProver()
Configure the ZK prover.
privchain.privacy.configureProver(config: ProverConfig): voidProverConfig
| Property | Type | Description |
|---|---|---|
mode | 'local' | 'remote' | Proving mode |
threads | number | CPU threads for local |
useGpu | boolean | Use GPU acceleration |
url | string | Remote prover URL |
apiKey | string | Remote prover API key |
IdentityModule
Access via privchain.identity.
create()
Create a new agent identity.
await privchain.identity.create(params?: CreateIdentityParams): Promise<Identity>CreateIdentityParams
| Property | Type | Description |
|---|---|---|
metadata | object | Optional metadata (encrypted) |
stake | number | Initial stake amount |
load()
Load an existing identity.
await privchain.identity.load(params: LoadIdentityParams): Promise<Identity>getReputation()
Get reputation for current identity.
await privchain.identity.getReputation(): Promise<Reputation>Reputation
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.
await privchain.identity.prove(params: ProveParams): Promise<Proof>ProveParams
| Property | Type | Description |
|---|---|---|
claim | string | Claim type (e.g., 'reputation') |
operator | 'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'range' | Comparison |
value | number | string | boolean | Value to compare |
min | number | Min for range proofs |
max | number | Max for range proofs |
verifyProof()
Verify an identity proof.
await privchain.identity.verifyProof(proof: Proof): Promise<boolean>stake()
Stake PRIV for reputation boost.
await privchain.identity.stake(params: StakeParams): Promise<string>delegate()
Delegate authority to another agent.
await privchain.identity.delegate(params: DelegateParams): Promise<Delegation>getAttestations()
Get all attestations for current identity.
await privchain.identity.getAttestations(): Promise<Attestation[]>issueAttestation()
Issue an attestation to another agent.
await privchain.identity.issueAttestation(params: IssueParams): Promise<string>WorkModule
Access via privchain.work.
registerAgent()
Register as a Proof of Agent Work worker.
await privchain.work.registerAgent(params: RegisterParams): Promise<string>RegisterParams
| Property | Type | Description |
|---|---|---|
capabilities | string[] | Agent capabilities |
stake | number | Stake amount (slashed if malicious) |
minReward | number | Minimum task reward |
onTask()
Listen for available tasks.
privchain.work.onTask(callback: (task: Task) => void): voidaccept()
Accept a task.
await privchain.work.accept(taskId: string): Promise<void>execute()
Execute a task with proof generation.
await privchain.work.execute(params: ExecuteParams): Promise<ExecuteResult>ExecuteParams
| Property | Type | Description |
|---|---|---|
taskId | string | Task ID |
input | any | Task input data |
executor | (input: any) => Promise<any> | Execution function |
getTaskHistory()
Get completed task history.
await privchain.work.getTaskHistory(limit?: number): Promise<TaskResult[]>Error Classes
import {
PrivChainError,
ConnectionError,
WalletError,
InsufficientFundsError,
TransactionError,
NetworkError,
NoteSpentError,
InvalidProofError,
PoolNotFoundError
} from '@privchain/sdk';Error Handling
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
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:
import type {
PrivChainConfig,
TransferParams,
DepositParams,
WithdrawParams,
Note,
Identity,
Reputation,
Proof,
Task,
// ... etc
} from '@privchain/sdk';