Session Client
The session client SDK handles the full buyer lifecycle: onboarding, session open, per-request payment with vouchers, and session close with on-chain settlement.
Quick Start
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buyerWallet | string | required | Buyer's Solana wallet address |
buyerSwigAddress | string | required | Buyer's Swig smart wallet address |
apiUrl | string | https://x402.dexter.cash | Settlement API base URL |
network | string | mainnet-beta | Solana cluster |
onProgress | function | none | Callback for lifecycle progress events |
Onboarding
Onboarding is a one-time process that provisions a Swig smart wallet and grants Dexter a scoped delegation role. The buyer proves wallet ownership with a SIWx (Sign-In-With-X) signature.
With @solana/kit (v2)
The SDK detects a Kit v2 CryptoKeyPair signer and uses it for both the SIWx proof and the Swig transaction signatures.
With @solana/web3.js (v1)
Onboard Options
| Parameter | Type | Description |
|---|---|---|
signer | CryptoKeyPair | Kit v2 signer. Handles SIWx and transaction signing. |
signMessage | (msg: Uint8Array) => Promise<Uint8Array> | Alternative: raw Ed25519 message signing function |
publicKey | string | Required with signMessage: wallet public key as base58 |
signTransaction | (tx) => Promise<tx> | Required with signMessage: transaction signing function |
Provide either signer (Kit v2) or signMessage + publicKey + signTransaction (web3.js / custom).
Session Lifecycle
open(params)
Opens a payment channel with a seller. Dexter verifies the buyer's Swig delegation role on-chain and creates the channel.
| Parameter | Type | Description |
|---|---|---|
seller | string | Seller's Solana wallet address |
deposit | string | Spend limit in atomic USDC units |
pay(channelId, params)
Requests a signed voucher from Dexter for a cumulative payment amount.
The amount is cumulative, not incremental. If you've made three requests at 10,000 each, the third voucher's amount is 30000, not 10000.
| Parameter | Type | Description |
|---|---|---|
amount | string | Cumulative total in atomic USDC units |
serverNonce | string | Nonce from the seller's challenge response |
close(channelId)
Closes the session and triggers on-chain settlement. Dexter executes a TransferChecked from the buyer's Swig wallet to the seller for the cumulative amount consumed.
Any deposit amount beyond what was consumed is not transferred. The buyer retains the unspent balance.
Progress Events
Track lifecycle events with the onProgress callback:
Event types: open, voucher, close, error.
Read Next
- Session Server for the seller-side integration
- Sessions Overview for the architecture and security model
- API Reference for endpoint schemas