XCN Decimal Handling

Critical information about XCN token decimal handling differences from Ethereum

⚠️ Critical: 8 vs 18 Decimals Discrepancy

triangle-exclamation

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

Context
Decimals
1 XCN equals
Used in

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.value in payable functions

  • address.balance queries

  • transfer() and call{value: }() operations

  • All 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_getBalance RPC calls

  • MetaMask balance displays

  • Ethers.js/Web3.js balance queries

  • Foundry's cast balance command

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

circle-exclamation

2. Event Emissions

3. Price Calculations

Migration Checklist

When migrating from Ethereum:

Summary

circle-check

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.

Last updated