For the complete documentation index, see llms.txt. This page is also available as Markdown.

XCN Decimal Handling

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

Native XCN has two representations:

Context
Precision

Native ledger

8 decimals (1 XCN = 100,000,000 tinyxcn)

EVM JSON-RPC

18-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.

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.

Last updated