CLI Reference
Thelegend-cli binary is a Rust-based tool for managing Legend Prime accounts, signing transactions, and running a local MCP server. It handles P256 key management, OAuth login, and direct API access.
Installation paths below are planned but may not yet be available. Check legend.xyz for the latest installation instructions.
Installation
Authentication
OAuth Login (recommended)
~/.legend/prod/profiles/default.json. No manual key management needed.
Query Key
--key flag > LEGEND_QUERY_KEY env > profile file.
Global Flags
| Flag | Description |
|---|---|
--profile <name> | Use a named profile (default: default) |
--key <qk_...> | Override auth with a query key |
--base-url <url> | Override API base URL |
--json | Force JSON output (default when piped) |
--quiet | Minimal output (IDs only) |
Commands
login
Authenticate via Google SSO and save the token to your profile.
whoami
Show current authentication info.
accounts
accounts list
List all sub-accounts.
accounts get <account_id>
Get details of a specific sub-account.
accounts create
Create a new sub-account.
--keygen, the CLI:
- Generates a P256 key in your Mac’s Secure Enclave (or on disk with
--use-file-key) - Sends the public key to Legend to create a Turnkey-backed sub-account
- Saves account details and key reference to your profile
plan
Create execution plans. Add --execute to automatically sign and execute in one step.
earn, swap, withdraw, transfer, borrow, repay.
plan execute
Execute a previously created plan with a signature.
sign
Sign an EIP-712 digest using the profile’s P256 key via Turnkey.
folio
View an account’s portfolio.
activities
View transaction history.
networks
List supported networks.
assets
List supported assets.
keygen
Generate a P256 keypair without creating an account.
config set
Set a configuration value.
mcp serve
Run a local MCP server via stdio. See MCP Setup for details.
Profile Storage
Profiles are stored at~/.legend/prod/profiles/<name>.json and contain:
- Authentication token (query key or JWT)
- P256 key reference (Secure Enclave label or file path)
- Associated account and Turnkey sub-org IDs
--use-file-key) are stored at ~/.legend/prod/keys/<name>.key with chmod 600.
Output Modes
- TTY (human): Formatted tables
- Piped /
--json: Raw JSON (default when stdout is not a terminal) --quiet: Just the primary identifier (account_id, plan_id, signature)
jq without extra flags: