Skip to main content
Pass token amounts as integer strings in the token’s smallest unit.

Definition

A human-readable amount includes the decimal point users see in wallets. A smallest unit amount is the integer value sent to APIs and contracts.
smallest_unit = human_readable_amount * 10^decimals

Decision Table

ProductWhere to read decimalsAmount fields
MultiversX Aggregator/api/v1/pair-configamountIn, amountOut, amountOutMin
Stellar Aggregator/api/v1/tokensamount_in, amount_out, amountIn, amountOut
Relayer and Gateway transactionsToken metadata or chain rulesvalue, ESDT transfer amounts, contract args

Worked Example

Convert 1 WEGLD with 18 decimals:
const human = "1";
const decimals = 18n;
const smallest = BigInt(human) * 10n ** decimals;
console.log(smallest.toString()); // "1000000000000000000"
Convert 100 USDC with 6 decimals:
const human = "100";
const decimals = 6n;
const smallest = BigInt(human) * 10n ** decimals;
console.log(smallest.toString()); // "100000000"

Edge Cases

CaseRiskFix
Floating-point conversionJavaScript number can round large values.Use BigInt, decimal libraries, or string parsers.
Assumed decimalsTokens can use different precisions.Read decimals from the product endpoint before quoting.
Human-readable amount sent to APIQuote amount is off by powers of ten.Convert before request construction.
Scientific notationAPIs expect integer strings.Serialize as base-10 strings without e.
Do not send human-readable amounts to quote endpoints. A decimal mistake can build a transaction for the wrong value.

Verify

Before signing or broadcasting, compare:
  • The input token decimals from metadata.
  • The integer string sent in the request.
  • The displayed human-readable amount in your UI.
  • The returned amountOut or amountIn converted back with output decimals.