ApiClient is the server-side interface to the CoinVoyage API. Import it from @coin-voyage/paykit/server and use it in your API routes, server actions, or backend services to create pay orders, retrieve quotes, manage KYC links, bank accounts, withdrawals, webhooks, and more. Every method returns an APIResponse<T> wrapper that provides consistent, type-safe error handling without throwing exceptions.
Initialization
string
required
Your organization’s API key from the CoinVoyage dashboard.
string
default:"production"
Environment to connect to:
"production" or "development".string
Optional session identifier attached to every request for tracking purposes.
string
Optional client version string sent as the
X-Client-Version request header.APIResponse<T>
EveryApiClient method returns a Promise<APIResponse<T>>. The response is always an object with either a data field (on success) or an error field (on failure) — never both.
Handling responses
T
The typed response payload. Present when the request succeeds.
object
Error details. Present when the request fails.
Methods
createDepositPayOrder
Creates a pay order with modeDEPOSIT for a direct on-chain deposit to a specified address.
params (PayOrderParams), opts? (Opts)
Returns: Promise<APIResponse<PayOrder>>
createSalePayOrder
Creates a pay order with modeSALE for a merchant sale. Requires your API secret for authorization.
If you omit intent.asset, CoinVoyage settles the payment to the settlement currency configured in your dashboard. If you provide intent.asset, the pay order settles to that specific asset and chain.
The authorization signature is generated internally. You only need to pass the raw
apiSecret string.- Dashboard settlement currency
- Specific settlement asset
Parameters:
params (PayOrderParams), apiSecret (string), opts? (Opts)
Returns: Promise<APIResponse<PayOrder>>
createRefundPayOrder
Creates a pay order with modeREFUND against an existing pay order. Supports full and partial refunds.
payOrderId (string), params (PayOrderParams), apiSecret (string), opts? (Opts)
Returns: Promise<APIResponse<PayOrder>>
getPayOrder
Fetches a pay order by its ID.payOrderId (string), opts? (Opts)
Returns: Promise<APIResponse<PayOrder>>
listPayOrders
Lists PayOrders for your organization with pagination. This is a signed server-side method and requires your API secret.params? (ListPayOrdersParams), apiSecret (string), opts? (Opts)
Returns: Promise<APIResponse<PayOrdersWithPagination>>
currencySearch
Searches supported currencies for token pickers and back-office tools.params (CurrencySearchParams), opts? (Opts)
Returns: Promise<APIResponse<CurrencySearchResponse>>
portfolio
Retrieves wallet token balances and USD values for a wallet address.params (WalletPortfolioRequest), opts? (Opts)
Returns: Promise<APIResponse<WalletPortfolioResponse>>
payOrderQuote
Generates a quote for a pay order given a user’s wallet and chain information. Returns available payment tokens with balances.payOrderId (string), params (PayOrderQuoteParams), opts? (Opts)
Returns: Promise<APIResponse<RouteQuote[]>>
payOrderPaymentDetails
Retrieves the information needed to complete a payment — destination address, amount, and per-step payment instructions.string
required
The unique identifier of the pay order.
string
default:"CRYPTO"
Payment rail to use. Defaults to
CRYPTO.object
Source currency to use for the payment details request, with
chain_id and address.string
Quote identifier from a previously selected route quote.
string
Address to which funds are returned if the payment fails.
Promise<APIResponse<PaymentDetails>>
getPayOrderPaymentMethods
Fetches the available payment methods (rails, tokens, availability) for a pay order.payOrderId (string), opts? (Opts)
Returns: Promise<APIResponse<PaymentMethodsResponse>>
KYC methods
Use these methods from server code to create verification links and check identity-verification status for your organization.createKYCLink
createKYCLink
Creates a KYC or KYB link for the authenticated organization. Requires your API secret.Parameters:
params (KYCLinkRequest), apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<KYCLinkResponse>>getKYCStatus
getKYCStatus
Retrieves the current KYC and terms-of-service status. Requires your API secret.Parameters:
apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<KYCLinkResponse>>Bank account methods
Use these signed server-side methods for fiat payout destination management.listBankAccounts
listBankAccounts
Lists bank accounts linked to the authenticated organization.Parameters:
apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<BankAccountsResponse>>getBankAccount
getBankAccount
Retrieves one linked bank account.Parameters:
bankAccountId (string), apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<BankAccountDetails>>addBankAccount
addBankAccount
Adds a new linked bank account. The request shape depends on the account type and payout currency.Parameters:
params (AddBankAccountRequest), apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<BankAccountDetails>>Withdrawal methods
Use these signed server-side methods to list and create off-ramp withdrawals.listWithdrawals
listWithdrawals
Lists organization withdrawals. Requires your API secret.Parameters:
apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<WithdrawalsResponse>>createWithdrawal
createWithdrawal
Creates an off-ramp withdrawal and returns wallet execution data when a source-chain transaction is required.Parameters:
params (CreateWithdrawalRequest), apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<WithdrawalResponse>>generateAuthorizationSignature
Generates an HMAC-SHA256 authorization signature for signed server-side API requests. MostApiClient methods that require signing generate this value internally when you pass apiSecret.
apiSecret (string), method (string), path (string)
Returns: string
subscribeOrderStatus
Opens a WebSocket connection for real-time pay order status events. Order-scoped subscriptions authenticate with your API key. Organization-wide subscriptions require a server-generated authorization signature forGET /ws.
OrderStatusSocket
The OrderStatusSocket exposes the following methods:
function
Subscribe to status events for a specific pay order.
function
Subscribe to all pay order events for your organization. Available only when
subscribeOrderStatus() is called with an authorization signature.function
Unsubscribe from a specific pay order.
function
Unsubscribe from organization-wide events. Available only when
subscribeOrderStatus() is called with an authorization signature.function
Attach a listener for parsed server messages.
function
Attach a listener for the WebSocket open event.
function
Attach a listener for the WebSocket close event.
function
Attach a listener for WebSocket errors.
function
Close the WebSocket connection.
Webhook methods
listWebhooks
listWebhooks
Lists all webhooks configured for your organization.Parameters:
apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<WebhookResponse[]>>createWebhook
createWebhook
Creates a new webhook subscription for your organization.Parameters:
params (CreateWebhookRequest), apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<WebhookResponse>>updateWebhook
updateWebhook
Updates an existing webhook subscription.Parameters:
webhookId (string), params (UpdateWebhookRequest), apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<WebhookResponse>>deleteWebhook
deleteWebhook
Deletes a webhook subscription.Parameters:
webhookId (string), apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<void>>Fee methods
getFeeBalances
getFeeBalances
Retrieves claimable fee balances for your organization.Parameters:
apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<GetFeeBalancesResponse>>claimFees
claimFees
Claims accrued fees for your organization.Parameters:
params (ClaimFeesRequest), apiSecret (string), opts? (Opts)Returns: Promise<APIResponse<ClaimFeesResponse>>Swap methods
swapQuote
swapQuote
Gets a quote for swapping between two currencies.Parameters:
params (SwapQuoteRequest), opts? (Opts)Returns: Promise<APIResponse<SwapQuoteResponse>>swapData
swapData
Gets the transaction data needed to execute a swap.Parameters:
params (SwapDataRequest), opts? (Opts)Returns: Promise<APIResponse<SwapDataResponse>>createPayOrder (low-level)
A lower-level helper that creates aDEPOSIT or SALE pay order with an explicit mode. In most integrations you should use the mode-specific helpers above (createDepositPayOrder, createSalePayOrder, createRefundPayOrder). Use createPayOrder only when you need direct control over the mode and authorization signature.
params (PayOrderParams), mode (CreatePayOrderMode), signature? (string), opts? (Opts)
Returns: Promise<APIResponse<PayOrder>>
ApiClient does not expose a processPayOrder() method. PayOrder processing begins automatically once funds are detected on-chain.TypeScript types
The SDK exports the following TypeScript types for use in your application.PayOrder
The main pay order object returned by API methods.PayOrderMode
PayOrderStatus
PayOrderMetadata
PayOrderParams
PayOrderIntent
IntentAmount
Provide eithertoken_amount or fiat — not both.
FulfillmentData
PaymentData
CurrencyAmount
string
Formatted display string suitable for rendering in UI.
string
Raw amount as a string to prevent BigInt precision loss.
number
USD equivalent value of the amount.