Cookbook
Recipes
Complete flows on the Path Global API, each one end to end in the sandbox with @pathglobal/sdk.
Path Global is an operator on the PATH network. Access to its API is on request at pathglobal.finance.
Each recipe runs in test mode, against the sandbox, and states what it needs first: the scopes of the key, and how many keys.
USD to EUR, priced on the pools
Fund a holding, price on the pools, route to an IBAN and read the receipt.
Open →A payment versus payment
Two holdings, two verdicts, one atomic exchange on the book.
Open →Close a clearing period
Record obligations, close and settle the period, read its signed report.
Open →A treasury transfer under dual control
One person proposes, another approves, the transfer executes.
Open →Credit a deposit to its holder
A subject, a PATH address, a vIBAN anchored to a holding, and a deposit.
Open →Assumed setup
npm install @pathglobal/sdkimport { PathGlobal } from '@pathglobal/sdk';
// A test key: key_test_…
export const pg = new PathGlobal({ apiKey: process.env.PATHGLOBAL_API_KEY! });Server-side. A key stays on your server. A recipe that needs a second key, for a second person or a second client, constructs a second client the same way.
The sandbox advances on its own
A route, a transfer or a period can answer before it is final. Read the object again until it is:
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
export async function until<T>(read: () => Promise<T>, done: (value: T) => boolean, attempts = 30): Promise<T> {
let value = await read();
for (let n = 0; n < attempts && !done(value); n++) {
await sleep(2000);
value = await read();
}
return value;
}The routes that fund a holding, simulate a deposit or close a cycle exist in test mode only. A live
key gets 404 pathglobal.core.not_found on each of them.
Errors
Every call that fails throws a PathGlobalApiError. Switch on code, and quote requestId to
Path Global support.
import { PathGlobalApiError } from '@pathglobal/sdk';
async function execute(quoteId: string) {
try {
return await pg.router.execute(quoteId, { idempotencyKey: `pay-${quoteId}` });
} catch (err) {
if (err instanceof PathGlobalApiError && err.code === 'pathglobal.router.quote_expired') {
return null; // The quote is past expires_at: quote again.
}
throw err;
}
}