CLI
The layerhop command line — chains, tokens, quotes, order status, deep links, project scaffolding and a local mock API for offline development and CI.
The layerhop command line (package @layerhop/cli) quotes swaps from your terminal, tracks orders, prints deep links and embed URLs, scaffolds projects and runs a local mock API (layerhop dev) for offline development and CI. It never signs or sends transactions.
How do I install it?#
npm install -g @layerhop/cli # or: npx @layerhop/cli <command>
layerhop --helpIt needs Node 20+. The build is a single file with no runtime dependencies, and it talks to the live API at https://api.layerhop.com by default.
How do I get a quote?#
layerhop quote 100 USDC base SOL solana \
--sender 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 \
--recipient 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWMThe output is a table with one row per provider, best first (marked *):
| Column | Meaning |
|---|---|
PROVIDER |
Provider id, for example relay or lifi. |
YOU GET / MIN |
Expected output and the minimum after slippage, in human units. |
ETA |
Estimated time to fill. |
FEE |
Total fee in bps: the LayerHop fee (20 on the api channel) plus any partner fee. |
GAS |
Estimated gas in USD. |
QUOTE ID |
The quoteId to build or simulate. |
The CLI takes <amount> in human units and converts it to base units with the token's decimals from the built-in token list. For any other token, pass base units with --base-units. Other options are --slippage-bps and --integrator. Add --json to get the raw QuoteResponse.
Which commands are there?#
| Command | What it does |
|---|---|
layerhop chains |
Supported chains (falls back to the built-in list when offline) |
layerhop tokens <chain> |
Tokens on a chain from GET /v1/tokens (falls back to the built-in list when offline) |
layerhop quote <amount> <token> <chain> <toToken> <toChain> --sender --recipient |
Ranked quotes, best first |
layerhop status <provider> <txhash> [--watch] [--interval s] |
Order status. --watch prints each change until the order is final. Exits 0 on filled, 1 on refunded / failed. |
layerhop link <amount> <token> <chain> <toToken> <toChain> |
A https://layerhop.com/swap?… deep link. Options: --recipient, --slippage-bps, --ref, --integrator. Add --embed for an /embed URL; it also takes --theme, --accent, --radius, --lock-src, --lock-dst and --hide-history. |
layerhop init [node|next] <dir> |
Scaffolds a minimal project that uses @layerhop/sdk: a Node script, or a Next.js app with a server-side quote route. It refuses a non-empty directory unless you pass --force. |
layerhop login [--api-key <key>] |
Checks an API key and saves it for this computer in ~/.config/layerhop/config.json (readable only by you, mode 600). Without --api-key it asks for the key without echoing it. Later commands use it when you pass no --api-key and LAYERHOP_API_KEY is unset. |
layerhop logout |
Deletes the saved key. |
layerhop listen --forward-to <url> |
Streams your account's webhook events (your key's mode) and POSTs each one to a local URL, signed with --secret / LAYERHOP_WEBHOOK_SECRET (or a new secret printed at start). --events a,b filters types. Reconnects until you stop it, and replays events created while it was disconnected. See Webhooks → Test locally. |
layerhop trigger <event-type> |
Sends a realistic sample event in test mode (order.filled, checkout.session.completed, …) to your test endpoints and to listen. Needs an lh_test_ key. |
layerhop events resend <evt_id> [--endpoint <whe_id>] |
Sends an event of your key's mode again, with the same id and payload, to the endpoints that subscribe to it (or only --endpoint) and to running listen sessions. |
layerhop usage [--bucket hour|day] [--key-id <key_id>] |
Requests, errors, p50 / p95 latency per endpoint group, error-code counts and the most recent failed requests of your key's account and mode (the dashboard's Usage page). --limit sets how many recent errors to show. |
layerhop deposit-address create <token> <chain> <toToken> <toChain> --recipient --refund-to |
Creates a deposit address and prints it with the rules to show your user. Options: --amount (human units, or base units with --base-units), --one-time (exactly --amount), --label, --metadata k=v,k=v, --integrator. Needs an API key. |
layerhop deposit-address list |
Your account's deposit addresses (--status active|disabled, --label, --limit, --cursor). |
layerhop deposit-address get <id> |
One address with its 20 most recent deposits. |
layerhop deposit-address refresh <id> |
Checks the address for deposits now. |
layerhop deposit-address disable <id> |
Stops tracking the address. |
layerhop deposit-address simulate <id> <amount> |
Records a fake deposit (human units, or --base-units). Needs an lh_test_ key; amounts ending in 4001 / 4002 (base units) are refunded / fail. |
layerhop dev |
Starts a local mock LayerHop API on http://127.0.0.1:8787 for offline development and CI: deterministic quotes, orders, status and signed webhooks. Options: --port, --host, --webhook-url, --secret, --fill-after <seconds>, --fork / --fork-chains (Anvil forks). See Local development. |
layerhop devnet |
Inside the monorepo, runs the real @layerhop/api with LAYERHOP_ENABLE_MOCK=1 PROVIDERS=mock. Elsewhere it points you to layerhop dev. |
Global options:
--api-url: envLAYERHOP_API_URL, defaulthttps://api.layerhop.com--api-key: envLAYERHOP_API_KEY, else the key saved bylayerhop login(LAYERHOP_CONFIG_DIRorXDG_CONFIG_HOMEmove the config directory)--json--help--version
How do I run LayerHop locally?#
npx @layerhop/cli dev # mock API on http://127.0.0.1:8787
export LAYERHOP_API_URL=http://127.0.0.1:8787 # the SDKs and the CLI read it
layerhop quote 100 USDC base SOL solana --sender 0x… --recipient 9WzD…layerhop dev needs no account, key, database or network. It serves the core API (chains, tokens, prices, quote, build, simulate, report, status, order list, and the webhook stream, trigger and resend that listen, trigger and events resend use) with fixed prices and the test-mode outcomes: an amount ending in 4001 refunds, 4002 fails and 4004 returns NO_ROUTE. Orders become final --fill-after seconds (default 5) after you report them, and --webhook-url sends signed order.* webhooks to your app. Its transactions are placeholders that move no funds, so never broadcast them. For CI, the setup-layerhop GitHub Action starts it for you. Local development has the details, including Anvil forks.
What exit codes does it use?#
0: success.1: an API error or a failed order. The CLI printserror: CODE: messageand a link to the error page.2: a usage error.
Not yet available
a local Solana test validator and a testnet faucet.
layerhop dev --forkforks EVM chains with Anvil; see Local development.
Last updated