1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// $ npm i qrcode
// $ node generate-qr.js taco-bell 0.1
const QRCode = require("qrcode");
const fs = require("fs");
// 1. Mock directory service (in production: GET https://api.solupg.dev/v1/resolve)
const DIRECTORY = {
"taco-bell": "4vyomkhcqdp66vzbq8gHcc3mPiRW2Mm8uFT7NVq88EH4",
};
async function main() {
const [alias, amountArg] = process.argv.slice(2);
const amount = amountArg ?? "0.1";
// 2. Resolve alias → wallet
const wallet = DIRECTORY[alias];
if (!wallet) throw new Error(`unknown alias: ${alias}`);
console.log(JSON.stringify({ alias: alias, wallet: wallet }, null, 2));
// 3. Build Solana Pay URL (bip-21)
const url = `solana:${wallet}`
+ `?amount=${amount}`
+ `&label=${encodeURIComponent("TacoBell")}`
+ `&memo=${encodeURIComponent("SolUPG Payment")}`;
console.log("url:", url);
// 4. Encode QR — pick one: terminal · base64 · PNG file
console.log(await QRCode.toString(url, { type: "terminal", small: true }));
const b64 = await QRCode.toDataURL(url); // base64 image
await QRCode.toFile("./checkout.png", url, { width: 512 }); // PNG file
console.log("✓ wrote checkout.png ·", b64.length, "b (data-url)");
}
main().catch(console.error);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Preferred: the SDK wraps resolve + pay + QR in one call
import { SolUPG } from "@solupg/sdk";
const upg = new SolUPG({ cluster: "mainnet-beta" });
const checkout = await upg.qr.create({
to: "taco-bell", // alias · email · phone · .sol · wallet
amount: 0.1,
token: "SOL",
label: "TacoBell",
memo: "SolUPG Payment",
});
// checkout.wallet → 4vyomkhcqdp66vzbq8gHcc3mPiRW2Mm8uFT7NVq88EH4
// checkout.url → solana:…?amount=0.1&label=TacoBell&memo=…
// checkout.png → base64 QR, 400×400
// checkout.reference → idempotency key — poll waitForPayment() with it
const status = await upg.qr.waitForPayment(checkout.reference);
# 1. Resolve alias
curl https://api.solupg.dev/v1/resolve?alias=taco-bell
# → { "alias": "taco-bell",
# "wallet": "4vyomkhcqdp66vzbq8gHcc3mPiRW2Mm8uFT7NVq88EH4" }
# 2. Create QR checkout
curl -X POST https://api.solupg.dev/v1/qr \
-H "content-type: application/json" \
-d '{"to":"taco-bell","amount":0.1,"token":"SOL","label":"TacoBell","memo":"SolUPG Payment"}'
# → { "url": "solana:4vyo…", "png": "data:image/png;base64,…", "reference": "…" }