Try it Live
Run Denomination examples in the interactive playground
WASM Implementation
WebAssembly-accelerated implementations of denomination conversions, compiled from Zig using ReleaseSmall mode.Overview
WASM implementations provide performance-critical denomination operations using compiled Zig code targeting WebAssembly. These are purely opt-in replacements for the JavaScript implementations with identical APIs. All WASM methods are compiled from denomination.zig withReleaseSmall optimization targeting minimal bundle size.
Quick Start
- Direct Import
- Selective Import
Performance
WASM implementations provide significant speedup for:- U256 arithmetic - Compiled Zig multiplication and division
- Bulk conversions - Processing many values in tight loops
- Constant-time operations - No JavaScript overhead
API Reference
WASM implementations match the standard Denomination API. See main documentation:- Wei -
from,fromGwei,fromEther,toGwei,toEther,toU256 - Gwei -
from,fromWei,fromEther,toWei,toEther,toU256 - Ether -
from,fromWei,fromGwei,toWei,toGwei,toU256
WASM-Accelerated Methods
All denomination conversions implemented in Zig:Wei
Gwei
Ether
Usage Examples
Bulk Gas Calculations
Balance Conversions
Real-Time Gas Price Tracking
Performance Characteristics
Multiplication (Upscaling)
Conversions that multiply are memory-bound:Gwei.toWei- multiply by 10^9Ether.toWei- multiply by 10^18Ether.toGwei- multiply by 10^9
Division (Downscaling)
Conversions that divide are compute-bound:Wei.toGwei- divide by 10^9Wei.toEther- divide by 10^18Gwei.toEther- divide by 10^9
Files
-
denomination.zig - Zig source implementation
- Location: src/primitives/Denomination/denomination.zig
- Defines
Wei,Gwei,Etherstructs - Implements all conversion methods
- Includes test suite
- Wei.wasm.ts - TypeScript WASM bindings for Wei
- Gwei.wasm.ts - TypeScript WASM bindings for Gwei
- Ether.wasm.ts - TypeScript WASM bindings for Ether
Zig Tests
The Zig implementation includes comprehensive tests:Benchmarking
Compare JS vs WASM performance:Limitations
WASM implementations have same behavior as JS:- Integer division - Fractional results truncate
- No overflow checks - U256 operations wrap
- Same API - Drop-in replacement
Related
- Wei - Wei API reference
- Gwei - Gwei API reference
- Ether - Ether API reference
- Conversions - Conversion details
- Uint WASM - Underlying U256 WASM implementation

