SDK Reference
The @zkp2p-pay/sdk package provides a simple interface for integrating ZKP2P Pay into your application.
Features
- Type-safe - Full TypeScript support with exported types
- Lightweight - No dependencies beyond shared types
- Flexible - Works in both browser and Node.js environments
- Multi-chain - Supports payments to Base, Ethereum, Arbitrum, and more
Quick Example
import { createCheckoutSession } from '@zkp2p-pay/sdk';
// Create a session on your backend
const response = await createCheckoutSession(
{
merchantId: 'merchant_123',
amountUsdc: '100.00',
destinationChainId: 8453,
destinationToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
recipientAddress: '0xYourWallet',
},
{
apiBaseUrl: 'https://api.pay.zkp2p.xyz',
apiKey: 'your_api_key',
}
);
// Redirect using the pre-built checkout URL
window.location.href = response.checkoutUrl;
Available Functions
| Function | Description |
|---|---|
createCheckoutSession | Create a new checkout session |
getMerchant | Fetch merchant profile and settings |
getCheckoutUrl | Get the checkout URL for a session |
redirectToCheckout | Redirect the browser to checkout |
createSessionAndRedirect | Create session and redirect in one call |
getMerchant
Fetch merchant profile including checkout defaults and enabled payment platforms.
Signature
function getMerchant(
merchantId: string,
opts: CheckoutClientOptions
): Promise<MerchantInfo>
Returns
interface MerchantInfo {
id: string;
name: string;
logoUrl?: string | null;
defaultChainId?: number | null;
defaultCheckoutMode?: 'exact-token' | 'exact-fiat' | null;
defaultMaxFeePercentage?: number | null;
enabledPaymentPlatforms?: string[] | null;
createdAt: string;
updatedAt: string;
}
Example
import { getMerchant } from '@zkp2p-pay/sdk';
const merchant = await getMerchant('merchant_123', {
apiBaseUrl: 'https://api.pay.zkp2p.xyz',
apiKey: 'your_api_key',
});
console.log('Merchant:', merchant.name);
console.log('Default chain:', merchant.defaultChainId);
console.log('Enabled platforms:', merchant.enabledPaymentPlatforms);
Configuration
All SDK functions require a CheckoutClientOptions configuration object:
interface CheckoutClientOptions {
apiBaseUrl: string; // Required: API server URL
apiKey: string; // Required: Your merchant API key
checkoutBaseUrl?: string; // Optional: Checkout UI URL
fetcher?: typeof fetch; // Optional: Custom fetch implementation
}
See Configuration for detailed options.
Installation
npm install @zkp2p-pay/sdk
Or with yarn:
yarn add @zkp2p-pay/sdk
See Installation for more details.