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

REPL

The interactive shell. Pre-wires a constructed ApyxClient against your active profile so you can try reads, writes, and ad-hoc viem calls without writing a script.

apyx repl

The first thing the REPL prints is a context banner — read it before running anything mutating:

$ apyx repl
@apyx-labs/sdk
profile: default (from /path/to/cwd/apyx.config.json)
chain:   ethereum (1)
rpc:     https://eth.llamarpc.com
account: 0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
LineMeaning
profile:Active profile name + which file it was read from. Says (overridden by --profile <name>) when set via flag.
chain:Human chain name + chainId.
rpc:Resolved RPC URL. Says (overridden) when --rpc-url was passed.
account:Active account address, or none for read-only profiles.

Injected globals

Every REPL session has these globals already resolved:

GlobalTypeNotes
apyxApyxClientThe full constructed client — apyx.publicClient, apyx.walletClient (if signer), apyx.addresses, apyx.apxUSD, apyx.apyUSD, apyx.apyUSDRateView?.
accountAccount | undefinedThe active viem Account, or undefined for read-only profiles.
chainChainviem’s Chain object for the active chain.
viem{ parseUnits, formatUnits, parseEther, formatEther, getAddress }Common helpers, no extra import required.
apyx> await apyx.apyUSD.exchangeRate()
1041273481200000000n

apyx> viem.formatUnits(await apyx.apyUSD.totalAssets(), 6)
'48912.43'

apyx> await apyx.apxUSD.balanceOf(account.address)
1234560000n

Top-level await is on by default. Tab completes dotted paths (apyx.apyUSD.<TAB> lists every method on the module).

Built-in commands

apyx> .help
.break   Sometimes you get stuck; this gets you out
.clear   Alias for .break
.editor  Enter editor mode
.env     Switch to another profile (.env <name>)
.exit    Exit the REPL
.help    Print this help message
.load    Load JS from a file into the REPL session
.save    Save all evaluated commands in this REPL session to a file

.env <name> swaps profiles in-place — the banner prints again, and all four globals (apyx, account, chain, viem) are reconstructed against the new profile.

apyx> .env base
@apyx-labs/sdk
profile: base (from /path/to/cwd/apyx.config.json)
chain:   base (8453)
rpc:     https://mainnet.base.org
account: 0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf

Session-start overrides do not follow .env. A --rpc-url override applies only to the initial profile; after .env <name> the new profile uses its own values from the config. Re-invoke the CLI if you want overrides on a different profile.

History

History persists across sessions at ~/.apyx/history. Up-arrow walks back, Ctrl-R searches incrementally. The default Node REPL cap of 30 lines is lifted — apyx keeps the full history.

A short writing transcript

apyx> await apyx.apxUSD.allowance(account.address, apyx.addresses.apyUSD)
0n

apyx> const tx = await apyx.apxUSD.approve({
        spender: apyx.addresses.apyUSD,
        amount:  viem.parseUnits('1', 6),
      })
{ hash: '0x3c6a…a9e1', wait: [Function: wait] }

apyx> await tx.wait()
{
  status: 'success',
  blockNumber: 19884112n,
  gasUsed: 48201n,
  ...
}

apyx> const dep = await apyx.apyUSD.deposit({
        assets:   viem.parseUnits('1', 6),
        receiver: account.address,
      })
apyx> await dep.wait()
{ status: 'success', blockNumber: 19884115n, gasUsed: 167822n, ... }

Exit

.exit, Ctrl-D, or Ctrl-C twice. On exit:

  • The Node REPL flushes history.
  • For signer.type = "ledger" profiles, the HID transport is closed cleanly (the device returns to its idle screen).