> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flynet.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Money + tokens

> How Flynet represents amounts on the wire.

All amounts on Flynet use a consistent wire shape:

```json theme={null}
{
  "value": "1000000000000000000",
  "currency": "FLY"
}
```

## Why stringified

`value` is a **stringified integer** in the smallest unit of
`currency`. For FLY, that means **wei**: 18 decimals of precision.
1 FLY = `"1000000000000000000"`.

The string format protects precision. Large FLY amounts exceed
JavaScript's `Number.MAX_SAFE_INTEGER`. Treat `value` as a string
and convert with `BigInt` when you need to do math.

## Formatting with the SDK

The published [`@flynetdev/core`](/concepts/typescript-client) SDK ships
`formatFly` and `formatUsdCents`, the recommended way to turn wire values
into display strings. Both are exact and string-based, with no precision
loss.

```ts theme={null}
import { formatFly, formatUsdCents } from "@flynetdev/core";

formatFly("25000000000000000001"); // "25.000000000000000001"
formatFly("1000000000000000000");  // "1"
formatUsdCents(1099);              // "10.99"
```

If you're not using the SDK, the hand-rolled equivalents below produce the
same results.

<Warning>
  **Chef's warning** - `wei / 1e18` and `Number(BigInt(wei) / BigInt(1e18))` both lose fractional FLY. The first silently rounds at \~16 significant digits; the second integer-truncates the fractional part entirely. Use one of the two correct approaches below.
</Warning>

### Quick display (lossy past \~16 significant digits)

```js theme={null}
const wei = response.amount.value;        // "1000000000000000000" (string)
const flyDisplay = Number(wei) / 1e18;    // 1
```

JavaScript `Number` is IEEE-754 double-precision. Anything beyond \~`2^53` significant digits loses bits. Fine for UI labels on amounts under \~9 quadrillion FLY; not fine for ledgering or comparisons.

### Exact display (string-based, no precision loss)

```js theme={null}
function formatFly(wei) {
  const s = String(wei).padStart(19, "0");
  const whole = s.slice(0, -18) || "0";
  const frac = s.slice(-18).replace(/0+$/, "");
  return frac ? `${whole}.${frac}` : whole;
}

formatFly("25000000000000000001"); // "25.000000000000000001"
formatFly("25000000000000000000"); // "25"
formatFly("1");                    // "0.000000000000000001"
```

Use the exact formatter for anything you'd round-trip back to wei, compare to thresholds, or sum across rows. Use the quick formatter only for fire-and-forget UI strings.

## USD amounts

Where the API expresses a USD value, it uses an **integer number of
cents**, not the `{ value, currency }` wire shape and not a floating-point
dollar amount. `1099` means `$10.99`. Integer cents avoid the rounding
errors of binary floating point, the same reasoning behind stringified FLY
wei. Format with `formatUsdCents` from the SDK:

```ts theme={null}
import { formatUsdCents } from "@flynetdev/core";

formatUsdCents(1099); // "10.99"
formatUsdCents(500);  // "5.00"
```

## Currency

Payment Intents are `FLY` only in v1. Other currency values are rejected
with HTTP 400 on routes that accept Money input.

## Common conversions

| FLY       | wei (`value`)              |
| --------- | -------------------------- |
| 0.001 FLY | `"1000000000000000"`       |
| 0.01 FLY  | `"10000000000000000"`      |
| 0.1 FLY   | `"100000000000000000"`     |
| 1 FLY     | `"1000000000000000000"`    |
| 10 FLY    | `"10000000000000000000"`   |
| 100 FLY   | `"100000000000000000000"`  |
| 1,000 FLY | `"1000000000000000000000"` |

## In requests

When sending Money to Flynet, use the same shape:

```json theme={null}
{
  "amount": {
    "value": "1000000000000000000",
    "currency": "FLY"
  }
}
```
