XCN Decimal Handling
Critical information about XCN token decimal handling differences from Ethereum
⚠️ Critical: 8 vs 18 Decimals Discrepancy
This is a fundamental difference from Ethereum that will cause bugs if not handled correctly.
Inside EVM: XCN uses 8 decimals (tinyxcns)
JSON-RPC: Returns 18 decimals (weixcns)
Conversion: 1 tinyxcn = 10^10 weixcns
Overview
On Goliath, the native XCN token has a unique decimal system that differs significantly from Ethereum's standard 18 decimals everywhere approach. This discrepancy exists between the internal EVM representation and the external JSON-RPC interface.
Quick Reference
EVM Internal
8
10^8 tinyxcns
msg.value, address.balance, Solidity
JSON-RPC
18
10^18 weixcns
eth_getBalance, MetaMask, web3.js
Conversion
-
1 tinyxcn = 10^10 weixcns
Between systems
Understanding the Two Systems
EVM Internal (8 decimals)
Inside smart contracts, all native token operations use tinyxcns with 8 decimal places:
This affects:
msg.valuein payable functionsaddress.balancequeriestransfer()andcall{value: }()operationsAll arithmetic with native token amounts
JSON-RPC Interface (18 decimals)
External tools and libraries see balances in weixcns with 18 decimal places:
This affects:
eth_getBalanceRPC callsMetaMask balance displays
Ethers.js/Web3.js balance queries
Foundry's
cast balancecommand
Conversion Formula
Practical Example
Consider an address with 9,000,099.81460509 XCN:
Inside Smart Contract
Via JSON-RPC
Verification
Smart Contract Development
❌ Common Mistakes
Best Practices
1. Define Clear Constants
2. Handle Payments Correctly
3. Balance Management
Frontend Integration
Sending Transactions
Reading Balances
Utility Functions
Testing Considerations
Hardhat Configuration
Test Examples
Common Pitfalls
1. Porting Ethereum Contracts
When porting Ethereum contracts, search for:
1 etheror1e18constantsUses of
etherkeywordHardcoded 18 decimal assumptions
2. Event Emissions
3. Price Calculations
Migration Checklist
When migrating from Ethereum:
Summary
Key Rules for Success:
Smart contracts: Always use 8 decimals (tinyxcns)
Frontend/RPC: Expect 18 decimals (weixcns)
Conversion: Remember the 10^10 factor
Testing: Verify both representations
Documentation: Always specify units clearly
The decimal difference between EVM internal (8) and JSON-RPC (18) is a fundamental characteristic of Goliath's XCN token. Understanding and properly handling this difference is crucial for building secure and functional applications on Goliath.
Related Resources
Last updated