
Philosophy
This module is a set of small, dependency-free utilities used across the other packages. It is intentionally generic — nothing here knows about Ethereum, chains, or transactions. Pure, side-effect-free, no third-party runtime dependencies. No new dependencies in @ethernauta/utils is a hard rule of the monorepo.
Modules
API
Hex ↔ bytes
import { bytes_to_hex, hex_to_bytes, strip_hex_prefix } from "@ethernauta/utils"
const hex = bytes_to_hex(new Uint8Array([0xde, 0xad, 0xbe, 0xef]))
const bytes = hex_to_bytes("0xdeadbeef")
const stripped = strip_hex_prefix("0xdeadbeef")
Hex ↔ number
import { hex_to_number, number_to_hex } from "@ethernauta/utils"
const hex = number_to_hex(255)
const value = hex_to_number("0xff")
Bytes ↔ unsigned integer
import { bytes_to_uint } from "@ethernauta/utils"
const n = bytes_to_uint(new Uint8Array([0x01, 0x00]))
RLP encoding
import { rlp_encode, type RlpInput } from "@ethernauta/utils"
const encoded = rlp_encode([
new Uint8Array([0x01]),
new Uint8Array([0x02, 0x03]),
])
Wei ↔ string formatting
import {
format_ether, format_gwei, format_unit,
parse_ether, parse_gwei, parse_unit,
} from "@ethernauta/utils"
format_ether(1_000_000_000_000_000_000n)
format_gwei(2_000_000_000n)
format_unit(123_456n, 4)
parse_ether("1.5")
parse_gwei("2")
parse_unit("12.34", 4)
Time helpers
import { seconds_to_big, now_to_big, deadline_in } from "@ethernauta/utils"
const now = now_to_big()
const in_one_minute = deadline_in(60)
const ms_as_bigint = seconds_to_big(30)
Case conversion
import { camel_to_kebab } from "@ethernauta/utils"
camel_to_kebab("transferFrom")
Type narrowing — invariant
import { invariant } from "@ethernauta/utils"
const input: string | null = "helloWorld"
invariant(typeof input === "string", "input must be a string")