Skip to main content

CLI

@4mica/cli puts 4Mica in your terminal. Use it to scaffold a project, create a wallet, deposit and withdraw collateral, pay for a 402-protected URL, and settle a cycle. Every command also works unattended, so agents and scripts can run it.

Install

Node.js 22 or later is required.
4mica autocomplete prints the steps to turn on tab completion in bash, zsh or PowerShell. To uninstall: npm uninstall --global @4mica/cli. Settings and wallet keys stay in ~/.config/4mica (%LOCALAPPDATA%\4mica on Windows). Those keys are the only copies: withdraw or back them up before deleting that directory.

From nothing to a paid request

Mint test USDC to the wallet’s address as Get test tokens describes. The new wallet needs no ETH: another wallet can send the mint, and the deposit is gasless. Then:
4mica status shows at any point whether the services answer, whether the wallet holds anything, and whether it has collateral. The CLI uses the Base Sepolia testnet unless told otherwise, even though the SDKs default to mainnet. --network ethereum-sepolia selects the other testnet. Real funds move only after --network base or 4mica config set network base. 4mica networks lists every network the CLI knows; see supported networks for which are live.

Commands

4mica help <command> shows a command’s examples and flags.

Your account

A wallet key is enough to deposit, pay and withdraw. Signing in is separate: it connects the CLI to your 4Mica account, so wallets you hold can be linked to it and shown in the dashboard.
auth login never asks for a password in the terminal. You approve the code at app.4mica.io/cli/authorize while signed in, and the CLI receives a token of its own, kept in the system keychain where there is one. Over SSH, --no-open prints the address to open on another device. Every signed-in terminal is listed under Settings → Developer, where it can be revoked. A token cannot move funds. It reads the account and links wallets; removing wallets has to be asked for with --scopes. Payments are still signed by the wallet key, which never leaves your machine. auth logout revokes a browser session, and leaves a dashboard token valid unless you pass --revoke. In CI, create a token under Settings → Developer → CLI sessions and set it as FOURMICA_TOKEN.

The wallet key

A wallet is a private key. The CLI takes it from the first of these that has one:
  1. --key-file <path>, a file holding only the key. - reads it from standard input; typed at a terminal, it is masked as you type.
  2. FOURMICA_WALLET_PRIVATE_KEY, exported in the shell. Meant for CI and containers: an exported key is visible to every program the shell starts. In an interactive shell prefer a key file.
  3. A .env file in the current directory, read automatically. --dotenv <path> reads another file instead.
  4. The key file named in the config file. wallets create and wallets use set it.
No flag takes the key itself, because flag values end up in shell history and in the process list. The key is never printed.
4mica wallets remove deletes the only copy of a key. Withdraw from the wallet first.

Sending money safely

Commands that sign (deposit, the withdrawals actions, cycles pay, cycles claim, cycles checkpoint) show what they are about to do (network, wallet, token and its address, amount in base units, how gas is paid, the contract) and ask before sending.
  • --dry-run (-n) checks that the command would work and sends nothing. It exits 1 when something blocks it, and the real command then refuses with NOT_READY without asking.
  • --yes skips the question. Without a terminal and without --yes, the command exits instead of waiting.
  • --gas on deposit, cycles pay and cycles claim picks who pays gas. auto, the default, uses a sponsored transaction when the network’s facilitator offers one; self always sends the wallet’s own transaction, which needs the network’s native token for gas.
  • On mainnet, or a core given by URL that is not on this machine, the question asks you to type the network’s name (or the core’s host), not y.
  • Once something is sent, its transaction hash is printed straight away. A failure or Ctrl-C after that point is reported as OUTCOME_UNKNOWN, with where to check: the transaction may still land, so do not run the command again until balance, withdrawals or cycles shows what happened.
fetch does not ask: --max is the consent. On a testnet it defaults to 1 USDC a payment; anywhere that may be real funds it needs --max, or --yes to accept that default, and stops with MAX_REQUIRED before sending anything otherwise. A URL that charges nothing needs no wallet. fetch --dry-run shows what a URL charges without paying. It still sends the request once, unpaid, and a URL that charges nothing answers it for real. After a deposit is mined, the CLI waits up to --timeout seconds for core to count it. If that runs out, the deposit is reported as pending and the command exits 0. Do not send it again.

Scripting

  • Standard output has the result and nothing else. Progress, questions, warnings and errors go to standard error. --quiet drops the progress.
  • --json prints the result as one JSON document. Field names are camelCase. An amount is a number in a string with its unit beside it, never inside it: "amount": "2.5", "asset": "USDC", and "amountRaw" for the base units.
  • Commands are described as data too. The package ships an oclif.manifest.json with every command, flag and allowed value.
  • --no-input guarantees no question is asked.
  • Errors carry a code, such as NO_SIGNER, INSUFFICIENT_BALANCE, UNREACHABLE, OUTCOME_UNKNOWN or CHECKPOINT_REQUIRED. With --json every failure, a mistyped command included, is printed on standard output as { "error": { "code", "message", "suggestions", "retryable", "details" } }. retryable says whether running the same command again is safe.
  • --debug (or DEBUG=4mica) prints each request and the stack of a failure to standard error, never a header, body or key.

Settings

Each setting comes from the first of: a flag, an environment variable, the project’s .env, the config file at ~/.config/4mica/config.json, the built-in default. 4mica config prints the result.
The environment variables are FOURMICA_NETWORK, FOURMICA_RPC_URL, FOURMICA_FACILITATOR_URL, FOURMICA_ASSET, FOURMICA_WALLET_PRIVATE_KEY, FOURMICA_TOKEN, FOURMICA_REQUEST_TIMEOUT and FOURMICA_DEBUG. Three more change how the CLI itself behaves: FOURMICA_API_URL points auth and account at another 4Mica platform API, FOURMICA_CREDENTIAL_STORE is file to keep the account token out of the system keychain or keychain to require it, and FOURMICA_NO_COLOR (like NO_COLOR) turns colour off. --rpc-url is a 4Mica core’s address, not an Ethereum RPC endpoint, and must be https unless it is on this machine. Requests honour HTTPS_PROXY, HTTP_PROXY and NO_PROXY.

Limits

  • Wallet keys are plain files readable by your user only. They are not encrypted, and a wallet key cannot be kept in the system keychain or on a hardware wallet yet.
  • The account token is stored separately from wallet keys: in the system keychain on macOS and on Linux with secret-tool, and elsewhere in a file readable by your user only.
  • One pending withdrawal per asset.
  • The CLI sends no telemetry and checks for no updates.