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
apyUSDRateViewis Ethereum-only. On Base the field isundefined— guard withapyx.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.comis 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:
test/e2e/sdk/apyUSD.fork.spec.ts—exchangeRateand the underlyingconvertToAssets(1e18)against an anvil mainnet fork.test/e2e/sdk/apyUSDRateView.fork.spec.ts— every read on the rate-view module.
The CLI surface is covered by
test/e2e/cli/methods.e2e.spec.ts.
Where to next
- Approve and deposit — the full apxUSD → apyUSD round-trip.
- Multi-chain — read the same value on both Ethereum and Base in one process.
- Custom RPC — wire in a paid endpoint.