@cosmosapp/pay_sdkServer

Quickstart

The smallest end-to-end flow: create a payment intent, complete it in the wallet, and validate the transaction.

If you just want to see a payment work end to end, start here. The first example is the shortest possible integration; the second shows the realistic server-creates / browser-completes split.

import { Client } from '@cosmosapp/pay_sdk';

const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });

// 1. Create a SEP-7 `pay` intent (no source → pay URI + QR).
const intent = await client.paymentIntents.createPay({
  destination: 'GCALNQQBXAPZ2WIRSDDBMSTAKCUH5SG6U76YBFLQLIXJTF7FE5AX7AOO',
  amount: '120.1234567',
  // Omitting asset fields uses native XLM on both testnet and mainnet.
  msg: 'Order #24',
});

console.log(intent.uri); // web+stellar:pay?destination=...
console.log(intent.qr);  // data:image/png;base64,...  (render this)

// 2. After the payer submits a transaction, validate it.
const outcome = await intent.validate('<txHash>');
if (outcome.valid) console.log('Settled!', outcome.status);

Full split (server creates, browser completes)

// ── server.ts ──────────────────────────────────────────────────────
import { Client } from '@cosmosapp/pay_sdk';
const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });

export async function createIntent() {
  const intent = await client.paymentIntents.createPay({
    destination: 'G...MERCHANT',
    amount: '10',
    // Native XLM keeps this first example network-independent.
  });
  return intent.toJSON(); // send this payload to the browser
}

export function confirm(intentId: string, txHash: string) {
  return client.paymentIntents.validate(intentId, { txHash });
}
// ── browser.ts ─────────────────────────────────────────────────────
import { WebClient } from '@cosmosapp/pay_sdk/web';

const intent = await fetch('/api/create-intent', { method: 'POST' }).then((r) => r.json());
const { txHash, account, wallet } = await new WebClient().pay(intent);

await fetch('/api/confirm', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ intentId: intent.id, txHash }),
});

References

  • Client: The main entry point of the SDK — a single, atomic client that exposes every resource through its own manager — an atomic, single-client design.
  • WebClient: The browser wallet client that detects the user's Stellar wallet, then builds, signs and submits the transaction

On this page