Skip to main content
The SDK exports pure utility functions and constants that have no client dependency. Import them from @oaknetwork/contracts-sdk or @oaknetwork/contracts-sdk/utils.

Hashing

keccak256(data)

Hashes a string, hex string, or Uint8Array using keccak256.

id(input)

Produces a bytes32 hash from a UTF-8 string. Equivalent to Solidity’s keccak256(abi.encodePacked(str)).

Encoding

isHex(data)

Type guard that checks if a string is a valid 0x-prefixed hex string.

toHex(value, options?)

Converts a value to a hex string. Pass { size: 32 } for fixed-length bytes32 encoding.

stringToHex(value)

Converts a UTF-8 string to a hex string.

isAddress(value)

Checks if a string is a valid Ethereum address.

getAddress(value)

Returns the checksummed version of an address. Throws if invalid.

Number formatting

parseEther(value)

Converts a human-readable ether string to bigint (wei).

formatEther(value)

Converts a bigint (wei) to a human-readable ether string.

parseUnits(value, decimals)

Converts a human-readable string to bigint with the specified decimal places.

Time helpers

getCurrentTimestamp()

Returns the current Unix time as a bigint in seconds.

addDays(timestamp, days)

Adds days to a Unix timestamp.

Chain helpers

getChainFromId(chainId)

Resolves a numeric chain ID to a viem Chain object. Falls back to a minimal definition for unknown IDs.

Browser wallet helpers

For frontend integrations:

Constants

CHAIN_IDS

BPS_DENOMINATOR

Basis-points denominator for fee calculations. 10_000n = 100%.

BYTES32_ZERO

Zero bytes32 value (0x0000...0000). Used as a default or unset marker.

DATA_REGISTRY_KEYS

Pre-computed keccak256 hashes for common registry keys:

scopedToPlatform(baseKey, platformHash)

Computes a platform-scoped registry key. Matches the on-chain DataRegistryKeys.scopedToPlatform.

Multicall

Batch multiple read calls into a single RPC round-trip. Pass an array of lazy closures — the same entity read methods you’d normally await individually.
For full usage details including cross-contract batching, see the dedicated Multicall page.

Viem re-exports

The SDK re-exports commonly used viem primitives so you don’t need to install viem separately: