Same dollar, different zeros: token decimals across chains

By Cleave Protocol

One USDC is a million units on Base and 10^18 units of pegged USDC on BNB Chain. How decimals work, and how to convert without a trillion-fold error.

Watch on YouTube

One USDC on Base is 1,000,000 base units. One pegged USDC on BNB Chain is 1,000,000,000,000,000,000 base units. The same displayed token quantity takes twelve more zeros on BNB Chain. Carry a raw amount from one chain to the other without converting it, and the number is wrong by a factor of a trillion.

Contracts store whole numbers

An ERC-20 token has no decimal point anywhere in its state. balanceOf returns a uint256. transfer takes a uint256. Every amount on chain is a whole number of the token's smallest unit.

A token can expose its display precision through the optional decimals() method. The ERC-20 standard describes it with an example: a value of 8 means dividing the token amount by 100000000 to get its user representation. The field changes how an amount is shown. It changes nothing about how the contract counts.

Six here, eighteen there

For USDC and USDT on the chains Cleave Protocol serves, the values are:

  • BNB Chain: pegged USDC and USDT use 18 decimals.
  • Ethereum, Arbitrum, Base, Optimism and Polygon: USDC and USDT use 6 decimals.

So the same symbol can mean different units depending on the chain. For example, decimals() returns 6 on USDC at 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 on Base, and 18 on pegged USDC at 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d on BNB Chain. A symbol is not enough to know the units. Read decimals for each token on each chain.

Converting between them

Between 6 and 18 decimals the factor is 10^12. Moving an amount into BNB Chain's units multiplies by it. Moving out divides by it. Integer division rounds toward zero, so anything past the sixth decimal is dropped. That remainder is dust.

function rescale(units: bigint, fromDecimals: number, toDecimals: number): bigint {
  if (toDecimals >= fromDecimals) {
    return units * 10n ** BigInt(toDecimals - fromDecimals);
  }
  return units / 10n ** BigInt(fromDecimals - toDecimals);
}

const onBnb = 1234567891234567891n;          // 1.234567891234567891 pegged USDC
const onBase = rescale(onBnb, 18, 6);         // 1234567n, that is 1.234567 USDC
const dust = onBnb - rescale(onBase, 6, 18);  // 891234567891n left behind

Two things in that snippet are deliberate. Amounts stay in bigint from end to end, because JavaScript's largest safe integer is 2^53 - 1, about 9 quadrillion, and an 18-decimal amount passes that at about 0.009 tokens. And the rounding direction is visible: going down loses the remainder, so any code that sends funds must decide what happens to it.

How it goes wrong

The trillion-fold error has two directions:

  • An amount of 1,000,000 units meant as one USDC on Base, read with 18 decimals on BNB Chain, becomes 0.000000000001 of a token.
  • An amount of 10^18 units meant as one pegged USDC on BNB Chain, read with 6 decimals elsewhere, becomes a trillion tokens.

The first quietly moves almost nothing. The second asks for a trillion times the intended amount. A short checklist guards against both:

  1. Keep amounts as integers in the token's own units. Never round-trip through floating point.
  2. Resolve decimals for the exact chain and token contract. If decimals() is unavailable, use verified metadata for that contract or stop the conversion.
  3. Convert only at the boundary where an amount changes chains or is shown to a person.
  4. Round down on purpose, and decide where the dust goes.
  5. Test every path with both a 6-decimal and an 18-decimal token.

In Cleave Protocol's agent tools

Cleave quotes swaps between any two of its six chains, BNB Chain included. Its agent tools take amounts in tokens, such as "25.5", not in raw units, so an agent does not need to know whether the token on that chain uses 6 or 18 decimals to ask for a quote. When it needs the units anyway, the token lookup tool returns each candidate's address and decimals.

Same dollar, different zeros.

The tool inputs, including how amounts are written, are on the MCP server docs page.