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

Read mainnet rate

The smallest possible end-to-end. Read the live apyUSD exchange rate and APY from Ethereum mainnet, format them for a human, exit cleanly. No wallet, no signing, no writes.

apyx apyUSD exchange-rate
apyx apyUSDRateView apy

What you’ll see

$ apyx apyUSD exchange-rate
1041273481200000000n

$ apyx apyUSDRateView apy
42345000000000000n

Both numbers are 18-decimal scaled bigints. 1.041e18 exchange rate means one apyUSD share is currently worth 1.041_273_481_2 apxUSD. 4.2345e16 APY means roughly 4.23% annualized.

Run it as a script

The same numbers from the SDK directly:

import { createApyxClient } from '@koed_jang/apyx-sdk';
import { http, formatUnits } from 'viem';
import { mainnet } from 'viem/chains';

const apyx = createApyxClient({
  chain: mainnet,
  transport: http(process.env.ETH_RPC_URL),
});

const [exchangeRate, apy] = await Promise.all([
  apyx.apyUSD.exchangeRate(),
  apyx.apyUSDRateView!.apy(),         // Ethereum-only
]);

console.log({
  exchangeRate: formatUnits(exchangeRate, 18),
  apy: `${(Number(formatUnits(apy, 18)) * 100).toFixed(4)}%`,
});

Promise.all on publicClient reads is essentially free — viem batches the JSON-RPC calls when the transport supports it.

Caveats

  • apyUSDRateView is Ethereum-only. On Base the field is undefined — guard with apyx.apyUSDRateView?.apy() if your code runs on both chains. See Supported Chains for the full per-chain availability matrix.
  • Public RPCs ratelimit. https://eth.llamarpc.com is fine for a one-shot read. For polling at a real cadence (every block, every 10s, etc.) drop in a private Alchemy / Infura / etc. URL — see the Custom RPC recipe.
  • Numbers are raw, not formatted. The SDK never formats — you do. Reach for viem’s formatUnits(value, 18) for human-readable strings.

Verifying the recipe

The SDK reads exercised here are covered by:

The CLI surface is covered by test/e2e/cli/methods.e2e.spec.ts.

Where to next