Divi Games

Courses / Game money

Amounts and base units

On the chain, amounts are decimal strings of base units, never floats.

TokenDecimals1 whole token in base units
GOLD2"100"
TDIVI8"100000000"

So the faucet's 1000 GOLD is 100000 base units, and tic-tac-toe's largest stake of 1000 GOLD is also 100000.

Why strings? JSON numbers are floating point in many languages and lose precision above 2^53. Balances are u128 in Rust, and strings carry them intact.

The SDK helpers

web/sdk/divigames.js converts for display and input:

formatAmount("100000", 2)   // "1000" (trailing zeros are trimmed)
parseAmount("12.5", 2)      // "1250"

Always do arithmetic on base units (integers) and only format at the edge.

Transfers

{ "type": "transfer", "to": "<address>", "token": "GOLD", "amount": "2500" }

moves 25.00 GOLD. A transfer larger than your balance fails with an Insufficient error that says what you needed and what you had.