DOCUMENTATION

XCN Decimal Handling

Correctly convert native XCN between ledger and JSON-RPC units.

Documentation

Native XCN has two representations:

ContextPrecision
Native ledger8 decimals (1 XCN = 100,000,000 tinyxcn)
EVM JSON-RPC18-decimal wei-style integers

One tinyxcn therefore equals 10^10 JSON-RPC units. Native XCN values sent through JSON-RPC must be a multiple of 10^10.

javascript

const RPC_UNITS_PER_TINYXCN = 10n ** 10n;

function alignNativeXcn(value) {
  return value - (value % RPC_UNITS_PER_TINYXCN);
}

This rule applies to native XCN only. ERC-20 tokens use the value returned by their own decimals() function. Current examples include WXCN and bridged ETH with 18 decimals, bridged USDC with 6, and stXCN with 18.

Do not use JavaScript BigInt directly in protobuf-js int64 fields. For native SDK code, use the integer type required by that SDK and keep the unit conversion explicit.