Skip to content
QSwapDocs

Amounts and units

Every token amount is a bigint of the token's smallest unit. Never a float.

Why amounts are bigintLive demo, running real codeType an amount. QSwap keeps every unit; floating point drops some.
Token decimals
Smallest units sent to the API
"98765432123456789"
Shown in the app
98,765,432
As a JavaScript number
98765432123456784
Precision lost: 5 smallest units sent to the api
Source: src/features/docs-site/units.ts → parseAmount(), formatAmount()

The rules

One amount, end to endLive demo, running real code
parseAmount1500000nSent to the API"1500000"Shown1.5

USDC, 6 decimals

Source: src/features/docs-site/units.ts

Parse once, at the edge

Typed text becomes a bigint through parseAmount(text, decimals). It returns undefined for anything that isn't a valid amount for that token.

Send strings

The API takes and returns amounts as decimal strings of the smallest unit: "1000000" is 1 USDC, "1000000000" is 1 SOL (9 decimals, in lamports).

Format only for display

formatAmount shows up to 6 significant digits on screen; whole numbers are never cut. The full value is in the tooltip.

Native SOL

SOL is the wrapped-SOL mint So11111111111111111111111111111111111111112 in every API payload, as Jupiter treats it. Jupiter wraps and unwraps it inside the swap transaction. MAX on SOL keeps a little back for fees and rent.