TypeScript SDK Quickstart
Install the @alexhalfborg/sgpaynowqr SDK and generate your first PayNow QR code end to end with createClient.
The official TypeScript SDK wraps the REST API with types, so you get autocompletion and validation without hand-writing requests. It works in Node.js and any modern runtime with fetch.
1. Install
npm install @alexhalfborg/sgpaynowqr2. Create a client and generate a QR
Pass your API key (created from the dashboard) to createClient. The request fields are identical to the REST body and use snake_case.
import { createClient } from "@alexhalfborg/sgpaynowqr";
const client = createClient("sgpn_your_api_key_here");
const { data } = await client.generate({
payment_type: "uen",
uen: "201234567A",
merchant_name: "My Company",
amount: 25.0,
reference: "INV001",
});
console.log(data.qr_string);3. Save the PNG image (optional)
When include_image is true (the default), the response includes a base64-encoded PNG you can decode and store.
import { writeFile } from "node:fs/promises";
const { data } = await client.generate({
payment_type: "mobile",
mobile_number: "+6591234567",
amount: 10.5,
include_image: true,
});
// data.qr_image_base64 is a base64-encoded PNG
await writeFile("qr.png", Buffer.from(data.qr_image_base64, "base64"));Next steps
Not sure which payment_type to use? Read Choosing a Payment Type. For production resilience, see Handling Errors and Rate Limits. The package is also on npm.