Introducing a new way to review your PRs.

Read the announcement

solana-foundation / pay

CLI for Agentic payments (x402, MPP, AP2).

View on GitHub

30 documents · Updated Nov 11, 2026

docs / cli-account-management

CLI account and wallet management

The CLI account system gives each payer identity a name, a network, and protected signing access. It lets an engineer create or bring in wallets, choose which wallet pays by default, inspect its public state, and remove it when it is no longer needed. For payment flows, this account state connects the user-facing commands to the payer used by the payment CLI and its payment operations. Remote signing accounts also connect to the provider model described in remote wallet providers.

Account registry

The account registry is the shared record of named payer identities. It lives at ~/…/accounts.yml and groups accounts by network, so a mainnet wallet is not silently used for local or test payments. The registry keeps the public address and the place that protects signing access; keychain-backed accounts do not put the secret key in the registry.

The registry supports these account kinds:

KindAccount role
Protected storeA wallet whose secret key is held by a platform store or 1Password.
File storeA wallet whose keypair is held in an owner-only file.
EphemeralA throwaway wallet used for non-mainnet work. Its keypair is kept with the network entry.
Remote signingA wallet whose key stays with a remote signing provider or hardware device. Provider credentials may be held in a platform secret store.

The registry also records one active account per network. Mainnet is the real-money network and is the default network for ordinary payer commands. Localnet and devnet accounts support isolated work without changing the mainnet payer.

Account command surface

The pay account command, also available as pay accounts, is the entry point for identity management. Running it without a subcommand shows the current account list and the available account actions.

CommandPurpose
pay account new NAMECreate and securely store a new payer identity, or connect a wallet held by a remote signing provider.
pay account import NAME FILEBring a Solana JSON or base58 keypair into the selected local protected store.
pay account list or pay account lsShow accounts grouped by network with their current state and balances.
pay account default NAMEMake a mainnet account the default payer.
pay account export NAME [PATH]Write a keypair JSON file for backup or use with Solana tools. Use - for standard output.
pay account remove NAMEPermanently remove an account. rm and destroy are aliases.

References: home/…/mod.rs• L64-73 home/…/mod.rs• L11-27 home/…/mod.rs• L43-67

Account lifecycle

Account management follows a simple lifecycle. A name first points to protected local or remote signing access, then becomes active when selected, and can later be exported or removed. Creation and import both write a mainnet account entry, while test networks can receive ephemeral accounts during payment setup rather than through the mainnet account commands. New-account setup also offers the funding flow and reports whether the payer is ready for paid requests.

The main lifecycle is shown below.

flowchart LR
    A[Create or import wallet] --> B[Store local key or provider access]
    B --> C[Register name and public address]
    C --> D[Select active payer]
    D --> E[Use in paid requests]
    C --> F[Export local key backup]
    D --> G[Remove account]
    G --> H[Delete registry entry and local access]

Account creation and import

pay account new NAME generates a new payer identity and asks where to protect its secret key when no store is given. It records the public address in the mainnet registry, runs the normal funding flow, and reports either the received funds or the top-up command still needed. A remote signing backend instead connects an existing provider or hardware wallet, resolves its public address, and records the provider wallet reference; it does not generate or import a local keypair. The browser-linked remote wallet is set up through pay setup --backend connect rather than this command.

Remote account setup collects the fields declared by the provider. Values can come from repeatable --credential KEY=@FILE flags or from provider-specific environment variables such as OPENFORT_SECRET_KEY; missing values are prompted for in an interactive terminal. Raw credential values in command arguments are rejected because process lists and shell history can expose them. The provider wallet can be selected with --wallet-id, an environment value, or an interactive choice when several wallets are available. A remote account is not saved until the provider confirms the wallet address.

pay account import NAME FILE accepts either a 64-byte Solana keypair in JSON form or the same keypair encoded as base58. It shows the public address and balance before the import, warns when the address already exists, and rejects an existing name or stored key unless --force is used. An imported account can also be made the default during the command. Remote signing backends do not accept this local key import path because their wallets remain in provider custody.

Both local commands support an explicit --backend when the CLI cannot ask a question. The supported choices depend on the operating system; a plain file is the headless fallback, and it is not encrypted by the CLI. Remote account creation can select a provider wallet by input or environment value, or prompt for one when several wallets are available. When setup completes, the CLI confirms the storage backend and gives a next step based on the funding result.

References: home/…/new.rs• L40-145 home/…/new.rs• L148-276 home/…/new.rs• L323-457 home/…/new.rs• L489-645 home/…/new.rs• L809-902 home/…/import.rs• L29-60 home/…/import.rs• L63-157

Account selection

Account selection decides which payer signs a request after the command has chosen a network. An explicit --account NAME has priority when the command supports it. Otherwise, the CLI uses the active account for that network; if no account is marked active, it uses the first name in sorted order.

The selection rules are:

  1. Use the named account from global --account NAME.
  2. Use the account marked active for the target network.
  3. If no account is marked active, use the first account by name.
  4. In sandbox or local mode, resolve the name within localnet rather than mainnet.
  5. If a non-mainnet network has no account, payment runtime paths may create an ephemeral wallet. Mainnet never creates a wallet silently.

pay account default NAME changes the active mainnet account and clears the active mark from the other mainnet accounts. It does not rename or copy a wallet. The --mainnet, --sandbox, and --local flags can force the network used by payment commands, while --account selects a name within that network.

References: home/…/accounts.rs• L442-515 home/…/accounts.rs• L768-848 home/…/signer.rs• L216-221 home/…/default.rs• L3-48 home/…/main.rs• L41-60 home/…/main.rs• L83-86 home/…/main.rs• L163-214

Account export

pay account export NAME converts the selected local account back to the JSON keypair format accepted by the Solana CLI. This is a recovery and interoperability path, so it requires access to the protected secret and writes a restricted file by default. A caller can provide a path, or use - when another process must receive the JSON through standard output. A remote signing account has no local keypair to export because its key remains with the provider or hardware device.

The default file name includes the account name and a short part of its public address. Exported key material must be treated as a full secret, even when the output is sent to a temporary path or a pipe.

References: home/…/export.rs• L3-18 home/…/export.rs• L20-68 home/…/accounts.rs• L316-412

Account removal

pay account remove NAME is a destructive action for the chosen network. The command displays the target account, offers to export a backup when a local key exists, asks for final confirmation, removes the local protected key or provider credentials, and removes the registry entry. Use --yes only when the surrounding process has already supplied its own approval.

For a remote signing account, removal either has nothing to delete locally when a hardware device holds the key or deletes the CLI's provider credential record when credentials are stored locally. In both cases, the wallet itself remains with the provider or on the device. For a file-backed keypair, the keypair is left on disk for manual removal because the file is treated as user-managed data. The command can also discover an older mainnet account that exists in a supported secret store but is not yet registered in accounts.yml.

When the removed account was the mainnet default, the CLI offers the remaining mainnet accounts as replacements. If no mainnet account remains, it tells the user to create one before making paid requests. The current removal path resolves a --sandbox target as localnet for lookup and display, but its registry deletion is mainnet-scoped; do not use that flag to assume a localnet entry is removed until this behavior is corrected.

References: home/…/destroy.rs• L8-70 home/…/destroy.rs• L72-165 home/…/destroy.rs• L167-218 home/…/destroy.rs• L222-291

Account state display

The CLI presents account state as a view of both local identity data and live chain data. pay account list groups rows by network, marks the active payer, shows the account name with its network and public address, and then reports token and credit balances when available. pay whoami adds the operating-system user and focuses on the resolved account for the selected network.

Account list output

The list view is the main status screen for account management. It reads every registered account, groups public addresses by their network endpoint, and fetches one balance batch per endpoint. This keeps accounts on different networks tied to the correct chain while avoiding duplicate balance lookups. The lookup groups and de-duplicates public addresses per endpoint, then runs the endpoint requests concurrently.

Each account row can show:

  • A filled marker for the active account on that network.
  • The account name, network, and public address.
  • Stablecoin, token, and credit balances with a symbol when one is known.
  • An api offline state and an Explorer link when balance lookup fails or the account has no balance result.
  • One mainnet-only prompt to run pay topup when no mainnet account has a displayed balance.

The output also works for accounts without a public address. In that case, the row states that the address is unavailable instead of presenting a misleading balance.

References: home/…/list.rs• L13-31 home/…/list.rs• L42-107 home/…/list.rs• L109-203 home/…/account.rs• L7-74

Active account identity

pay whoami first prints the operating-system user, then resolves and displays the payer account. With no account override it uses the active account for mainnet; with an account or network override it reports the requested scope. It fetches stablecoin balances for that same network and links to the matching Explorer cluster when the lookup is not available.

This command is useful for checking payer context before a paid operation. A missing account is reported as a setup state rather than as a signing failure, while a missing public address is reported as an incomplete account record.

References: home/…/whoami.rs• L1-10 home/…/whoami.rs• L24-72 home/…/whoami.rs• L74-111

Wallet protection

The account name is a label for a payer, not the secret itself. Mainnet local secret-key access normally passes through the selected store's approval gate, while remote accounts keep the signing key with the provider or hardware device and protect provider credentials locally only when required. Ephemeral accounts are intentionally ungated and are limited to non-mainnet use. Payment code loads local secret access or remote signing access only after it has resolved the account and network.

The protection boundary is important when moving between commands:

Account stateSecret-key locationMain concern
Keychain, keyring, Windows Hello, or 1PasswordExternal protected storeThe store must be available on the current machine and may require approval.
FileAccount-specific keypair fileThe file is owner-only but is not encrypted by the CLI.
Remote signingProvider or hardware custody; provider credentials may be in a platform secret storeThe provider or device connection must work, and removing the CLI account does not remove the provider wallet.
EphemeralAccount registry entryThe key is suitable for sandbox-style work, not real-money storage.

References: home/…/accounts.rs• L65-87 home/…/accounts.rs• L107-172 home/…/accounts.rs• L316-412 home/…/new.rs• L323-457

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the command aliases and positional account names aligned across AccountCommand, the account subcommands, and the top-level Command enum.
  • Keep active-account rules aligned between the registry resolver, pay account default, pay whoami, and the global --account and network flags.
  • Keep the account kind stored in accounts.yml aligned with the signer loader and the removal path. A mismatch can make an account visible but unusable or leave its secret behind.
  • Keep local and remote account records aligned with their access paths. A remote provider and wallet reference must resolve before credentials are stored or used.
  • Keep balance display network routing aligned with the RPC selected for mainnet, localnet, and devnet. A wrong endpoint can report a valid wallet as empty.
  • Keep balance batching aligned with the network used for each account. A shared public address can have different balances on different endpoints.
  • Keep export format compatible with import and the Solana CLI. Changes to keypair length or byte order can make backups unusable.
  • Keep remote credential names and wallet identifiers aligned across command flags, environment values, provider fields, and provider-side wallet selection.
  • Keep remote wallet setup boundaries aligned. Browser-linked wallets use pay setup --backend connect, while provider-backed wallets use the remote account path.
  • Keep the network used for destroy lookup, secret cleanup, and registry deletion identical, especially for sandbox accounts.

Important failure modes

TriggerConsequenceGuard
Mainnet has no configured accountPaid commands cannot find a safe payer.Run pay setup or pay account new NAME; mainnet does not create an ephemeral wallet silently.
--account NAME is not present on the forced networkThe command stops before it can sign with another network's wallet.Use a name registered under the selected network.
Protected store, hardware device, or remote provider access is unavailableImport, export, signing, or removal cannot reach the required local secret or provider connection.Restore the store, device, or provider session, then retry with a supported backend.
A remote account has no valid credentials or provider walletAccount creation cannot verify an address and does not save a usable account.Supply provider fields through protected files, environment values, or an interactive terminal.
A remote credential is passed as a raw command argumentThe command rejects it before account creation.Use --credential KEY=@FILE or the provider-specific environment variable.
pay account new runs without a backend and without a terminalThe CLI cannot choose a store or prompt for setup.Pass an available --backend and all required remote inputs.
Balance service or RPC lookup failsThe CLI shows api offline or an Explorer link instead of treating the balance as zero.Check the selected RPC and service, then run the account status command again.
Accounts on several networks share a public addressA balance can be shown from the wrong chain if endpoint grouping is changed incorrectly.Keep each network mapped to its own RPC endpoint.
--sandbox is used with account destructionThe command can identify a localnet account but remove a same-name mainnet entry instead of the localnet entry.Do not rely on sandbox destruction until registry deletion uses the selected network.
A file-backed account is removedThe registry entry is gone but the keypair file remains.Remove the user-managed keypair file separately when it is no longer needed.
A remote account is removedCLI credentials and the registry entry are gone, but the provider wallet still exists.Remove or disable the provider wallet separately when its external lifetime is over.
An exported JSON file is exposedAnyone with the file can act as the payer.Protect the export, transfer it only through a trusted channel, and delete temporary copies.

Key files

FileWhy to read it
rust/…/accounts.rsDefines the account registry, network grouping, active-account rule, storage model, and ephemeral-wallet behavior.
rust/…/mod.rsDefines the account command surface, aliases, and no-subcommand behavior.
rust/…/new.rsShows how local payer identities are created, how remote or hardware wallets are connected, how setup selects storage, and how the CLI reports funding results.
rust/…/import.rsShows the key import formats, duplicate handling, and registration flow.
rust/…/list.rsDefines the account list view, network-aware balance lookup, and status display.
rust/…/default.rsDefines mainnet default-account selection.
rust/…/export.rsDefines backup and Solana-compatible key export.
rust/…/destroy.rsDefines confirmation, legacy account discovery, local or remote access removal, and default replacement behavior.
rust/…/whoami.rsShows how the CLI presents the resolved payer and its balances.
rust/…/account.rsKeeps account headers, balance errors, Explorer links, and top-up hints consistent across views.
rust/…/signer.rsShows how a registered account becomes a signing identity and how protected stores differ from ephemeral or remote accounts.
rust/…/main.rsDefines global account and network overrides before payment commands run.