Skip to main content

SDK Guide

The PayChain SDK is the recommended integration path for Node.js and TypeScript backends. It wraps the same public REST API with typed helpers, safer payout split handling, idempotency support, error mapping, and webhook verification utilities.
Positioning note: Use the SDK when your backend runs Node.js or TypeScript. Use the REST API directly when you need another language, full HTTP control, or your own wrapper.

Install

Create a client

What the SDK covers

  • Customers.
  • Invoices.
  • Payout route attachment.
  • Dynamic payout recipients.
  • Withdrawals.
  • Webhooks.
  • Balances.
  • Transactions.
  • Networks.
  • Tokens.

What the SDK does not cover

  • Account settings, API key management, billing changes, and payout-route administration that are handled in the dashboard.
  • Unsupported or private beta surfaces that are not part of the public API.
  • Low-level custody, infrastructure, or treasury implementation details.
Security note: The SDK is server-side only. Do not bundle it into browser or mobile apps with API keys.

Idempotency

Every mutating operation should include an idempotency key.

Customer deposit addresses

For reusable customer deposit-address flows, ensure the customer has an address for the rail before showing payment instructions. ensureAddress returns an existing address when one already exists, or creates a missing address when the business is configured for the requested rail. Call it before displaying a reusable address, not only during customer creation. This lets existing customers receive newly supported rail addresses as PayChain adds networks over time.

Solana

Stellar dedicated addresses

Most Stellar invoice and Auto Deposit Intent integrations do not need ensureAddress. By default, PayChain returns the business Stellar treasury address plus a required Memo ID:
Address selection note: Non-EVM reusable-address flows must use the address returned for the requested rail, such as chainFamily: "sol" with networkId: "sol-mainnet" or, when explicitly using Stellar dedicated addresses, chainFamily: "stellar" with networkId: "stellar-mainnet". Never fall back to ethAddress, the first customer address, or any 0x... address when a Solana or Stellar address is expected.
Lazy provisioning note: PayChain can create a missing customer address for a supported rail on demand. If only one active network matches the requested rail, PayChain may infer networkId, but SDK integrations should pass networkId explicitly for a predictable address-selection pattern.

Invoice confirmation progress

Use invoices.get to poll canonical invoice state while a payment is waiting for required network confirmations.
Fulfillment note: Wait for paid or overpaid invoice status before fulfilling. Confirmation progress is for customer-facing visibility while settlement finality is still pending.

Webhook verification

Webhook verification must use the raw request body.
Raw body note: Do not parse and re-stringify JSON before verifying. Use the exact bytes PayChain sent.

When to use REST instead

Use REST directly when:
  • Your backend is not Node.js or TypeScript.
  • You need language-specific HTTP instrumentation.
  • You want to build your own wrapper.
  • You need to inspect exact request and response payloads.
  • You are debugging endpoint-level behavior.