Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Pratyay360/upiqrcode/llms.txt

Use this file to discover all available pages before exploring further.

svg_qr_code() takes any string and returns an SVG QR code. It skips URL construction and field validation entirely, giving you direct control over what gets encoded. Prefer this function over upiqrcode() when you have already built a UPI intent URL yourself, need to encode a non-UPI string, or want to apply custom parameter formatting before encoding.

Function signature

function svg_qr_code(intent: string): Promise<string>

Parameters

intent
string
required
The string to encode as a QR code. This is typically a UPI intent URL you have constructed yourself (e.g. upi://pay?pa=merchant@upi&pn=Acme), but the function accepts any non-empty string.

Returns

Returns
string
required
SVG markup string of the generated QR code (minimum 200×200 px). Inject this into the DOM with innerHTML or, in React, with dangerouslySetInnerHTML.

Errors

The returned Promise rejects with a string error message (e.g. "QR encode error: <detail>") if the QR encoding step fails internally.

Usage example

import init, { svg_qr_code } from 'upiqrcode';

async function renderCustomQR() {
  // Load the WebAssembly module once before calling any function.
  await init();

  // Build the UPI intent URL yourself for full control over parameters.
  // Note: svg_qr_code() applies its own percent-encoding, so pass the
  // raw (unencoded) intent string. Do not pre-encode with URLSearchParams.
  const intentUrl =
    'upi://pay?pa=merchant@upi&pn=Acme Store&am=500.00&cu=INR&tn=Invoice #2088';

  try {
    const svgMarkup = await svg_qr_code(intentUrl);
    document.getElementById('qr-container')!.innerHTML = svgMarkup;
  } catch (err) {
    console.error('QR generation failed:', err);
  }
}
Use upiqrcode() if you want the library to construct the UPI URL and validate required fields for you. Use svg_qr_code() if you need direct control over the URL structure, or if you want to encode any arbitrary string as a QR code.

Build docs developers (and LLMs) love