dero-pay
API Reference

API Reference

Complete reference for all dero-pay package exports.

Core (dero-pay)

Types, pricing utilities, and payment ID generation.

import {
  // Pricing
  deroToAtomic,              // Convert DERO string to atomic BigInt
  atomicToDero,              // Convert atomic BigInt to DERO string
  formatDero,                // Format atomic units as "X.XXXX DERO"
  isValidAmount,             // Validate amount is positive and valid
 
  // Payment IDs
  generatePaymentId,         // Generate random uint64 payment ID
  paymentIdToHex,            // Convert payment ID to hex string
  hexToPaymentId,            // Convert hex string to payment ID
  isValidPaymentId,          // Validate payment ID format
 
  // Constants
  ATOMIC_UNITS_PER_DERO,     // 100_000n (10^5)
  DERO_DECIMALS,             // 5
 
  // Types
  type Invoice,
  type InvoiceStatus,        // "created" | "pending" | "confirming" | "completed" | "expired" | "partial"
  type Payment,
  type PaymentStatus,
  type WalletStatus,
  type CreateInvoiceParams,
  type CreateInvoiceEscrowParams,
  type InvoiceEscrow,
  type EscrowInvoiceStatus,
  type DeroPayConfig,
  type DeroChainId,
  type WebhookEvent,
  type WebhookEventType,
  type DeroPayError,
  type DeroPayErrorCode,
} from "dero-pay";

RPC (dero-pay/rpc)

import {
  WalletRpcClient,   // DERO wallet JSON-RPC client
  DaemonRpcClient,   // DERO daemon JSON-RPC client
 
  type WalletRpcConfig,
  type DaemonRpcConfig,
  type GetTransfersParams,
  type GetTransfersResult,
  type TransferEntry,
  type TransferParams,
  type MakeIntegratedAddressParams,
  type GetInfoResult,
  type GetScParams,
  type GetScResult,
  type InvokeScParams,
  type InstallScParams,
} from "dero-pay/rpc";

Server (dero-pay/server)

import {
  // Core
  InvoiceEngine,
  PaymentMonitor,
  WebhookDispatcher,
 
  // Storage
  MemoryInvoiceStore,        // In-memory (dev)
  SqliteInvoiceStore,        // SQLite (production, requires better-sqlite3)
 
  // Webhook helpers
  createWebhookEvent,
  signWebhookPayload,
  verifyWebhookSignature,
 
  // Re-exported from other modules
  WalletRpcClient,
  DaemonRpcClient,
  EscrowContract,
  EscrowManager,
 
  // Types
  type InvoiceStore,         // Interface for custom storage backends
  type InvoiceFilter,
  type InvoiceStats,
  type InvoiceEngineEvents,
  type PaymentMonitorEvents,
  type SqliteStoreConfig,
  type WebhookConfig,
  type WebhookDelivery,
  type EscrowRecord,
  type EscrowStatus,
  type EscrowManagerConfig,
} from "dero-pay/server";

Client (dero-pay/client)

import {
  XSWDPayClient,       // Browser-side XSWD client for payments
  PaymentSession,      // Payment session manager
 
  type XSWDPayAppData,
  type XSWDPayEvents,
  type PaymentSessionEvents,
} from "dero-pay/client";

React (dero-pay/react)

import {
  DeroPayProvider,       // Context provider
  PayWithDero,           // "Pay with DERO" button (XSWD)
  InvoiceView,           // Full payment interface (QR, address, timer)
  PaymentStatus,         // Compact status indicator
  EscrowInvoiceView,     // Escrow-specific payment view
  useDeroPayContext,     // Hook for custom payment UIs
 
  type DeroPayProviderProps,
  type DeroPayContextValue,
  type PayWithDeroProps,
  type InvoiceViewProps,
  type PaymentStatusProps,
  type EscrowInvoiceViewProps,
} from "dero-pay/react";

Next.js (dero-pay/next)

import {
  createPaymentHandlers,    // Factory for API route handlers
  createDeroPayMiddleware,  // API key middleware
  generateApiKey,           // Generate a random API key
 
  type PaymentHandlersConfig,
  type DeroPayMiddlewareConfig,
} from "dero-pay/next";

createPaymentHandlers Return Value

const {
  createInvoiceHandler,  // POST — create invoice
  statusHandler,         // GET  — invoice status by ID
  listInvoicesHandler,   // GET  — list invoices with filters
  statsHandler,          // GET  — invoice statistics
  webhookHandler,        // POST — incoming webhook receiver
  healthHandler,         // GET  — engine health check
  escrowActionHandler,   // POST — escrow lifecycle actions
  listEscrowsHandler,    // GET  — list escrow records
  getEngine,             // () => Promise<InvoiceEngine>
} = createPaymentHandlers(config);

Escrow (dero-pay/escrow)

import {
  EscrowContract,         // Smart contract RPC wrapper
  EscrowManager,          // Lifecycle manager
 
  // Status utilities
  EscrowStatusCode,       // { AWAITING_DEPOSIT: 0, FUNDED: 1, ... }
  statusCodeToString,     // Convert code to human-readable string
 
  type EscrowStatus,
  type EscrowStatusCodeValue,
  type EscrowOnChainState,
  type EscrowRecord,
  type EscrowResolution,
  type EscrowManagerEvents,
  type EscrowManagerConfig,
  type CreateEscrowParams,
} from "dero-pay/escrow";

See the Escrow documentation for full escrow API details.

Configuration Reference

FieldTypeDefaultDescription
walletRpcUrlstringlocalhost:10103Wallet RPC endpoint
daemonRpcUrlstringlocalhost:10102Daemon RPC endpoint
rpcAuth{ username, password }RPC authentication
chainIdDeroChainId"dero-mainnet"Network identifier
defaultTtlSecondsnumber900Invoice expiration (15 min)
defaultRequiredConfirmationsnumber3Confirmation depth
pollIntervalMsnumber5000Monitor poll interval
webhookUrlstringWebhook destination
webhookSecretstringHMAC signing secret
webhookMaxRetriesnumber3Max delivery attempts
storeInvoiceStoreMemoryInvoiceStoreStorage backend
enableEscrowbooleanfalseEnable escrow subsystem
escrowFeeBasisPointsnumber0Escrow platform fee in basis points (0 = no fee, 250 = 2.5%)
escrowBlockExpirationnumber60Escrow block expiry