Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Addresses

The address registry, the lookup function, and the type. For the human-readable matrix and Etherscan/Basescan links, see Supported Chains.

import { APYX_ADDRESSES, getAddresses, type ApyxAddresses } from '@koed_jang/apyx-sdk';

ApyxAddresses

type ApyxAddresses = {
  apxUSD: Address;
  apyUSD: Address;
  apyUSDRateView?: Address;
};

apxUSD and apyUSD are required; apyUSDRateView is optional — chains where the rate-view contract isn’t deployed simply omit the field.

APYX_ADDRESSES

The built-in registry, keyed by chainId:

const APYX_ADDRESSES: Record<number, ApyxAddresses> = {
  1: {
    apxUSD: '0x98A878b1Cd98131B271883B390f68D2c90674665',
    apyUSD: '0x38EEb52F0771140d10c4E9A9a72349A329Fe8a6A',
    apyUSDRateView: '0xab3Aa53D942cbFb58773856BdE4F3c3EFbaf0fDc',
  },
  8453: {
    apxUSD: '0xD993935E13851dd7517af10687EC7e5022127228',
    apyUSD: '0x2c271ddF484aC0386d216eB7eB9Ff02D4Dc0F6AA',
  },
};

This constant is not frozen when imported — if you absolutely need to mutate it (e.g. injecting a fork chain in a test harness), you can. Most consumers should prefer addresses overrides on createApyxClient instead, which leaves the registry untouched.

getAddresses(chainId)

The lookup helper. The same call createApyxClient makes internally.

function getAddresses(chainId: number): ApyxAddresses;
Behaviour
Known chainIdreturns the entry from APYX_ADDRESSES.
Unknown chainIdthrows UnsupportedChainError.

Useful when you want to read addresses without constructing a full client (e.g. logging a startup banner).

Override semantics

createApyxClient({
  chain: mainnet,
  transport: http(),
  addresses: { apyUSD: '0xFork…' },
});

The addresses field is Partial<ApyxAddresses>. The factory does:

const merged = { ...APYX_ADDRESSES[chain.id], ...overrides };

so you can override one field, two fields, or all three. The merge respects undefined: passing addresses: { apyUSDRateView: undefined } does not strip the field — use addresses: {} (or omit the key) to keep the built-in value, and pass an explicit address only when you want to replace it.

Validation and freezing

After merge, createApyxClient runs each non-null field through viem.isAddress(value, { strict: true }):

Validation ruleEffect
Must begin with 0xelse InvalidAddressError
Must be exactly 42 chars (0x + 40 hex)else InvalidAddressError
Either all-lowercase or correctly EIP-55 mixed-caseelse InvalidAddressError

The validated ApyxAddresses is then Object.freezed. The result exposed as apyx.addresses is therefore:

  • Guaranteed valid (no further validation needed downstream).
  • Guaranteed checksummed (read-out form is canonical regardless of input case).
  • Guaranteed immutable (mutation attempts silently fail in non-strict mode, throw under 'use strict').

Consumers in code

Source: src/addresses.ts. The CLI’s config respects address overrides via three flags: --address-apxusd, --address-apyusd, --address-rate-view. They map 1:1 onto this object’s three fields.