Overview
Every command that needs a private key follows the same lookup order. This avoids requiring--private-key on every command while still allowing explicit overrides.
Private Key Lookup Order
--private-key <path>flag (if provided) — Use this file directly.COWBOY_PRIVATE_KEYenvironment variable — If set, treat the value as a hex-encoded 32-byte private key..cowboy/config.json— Readkey_filefrom the active environment, resolved relative to.cowboy/..cowboy/key— Fallback for backward compatibility (walk up from the current directory to find the nearest.cowboy/keyfile, same pattern as.git/discovery).
Key File Formats
The CLI supports two key file formats and auto-detects which is in use: PEM format (current default):0x prefix is accepted but not required for hex format. Trailing newlines are trimmed. Use cowboy wallet upgrade to convert hex keys to PEM format.
Directory Walking
The CLI searches for.cowboy/ starting from the current working directory and walking up to the filesystem root:
RPC URL Discovery
The same pattern applies to the RPC URL:--rpc-url <url>flag (if provided).COWBOY_RPC_URLenvironment variable..cowboy/config.jsonfile (readrpc_urlfrom the active environment).- Default:
http://localhost:4000.
config.json format (multi-environment):
Commands Using Auto-Discovery
Every command that needs a private key or RPC URL uses auto-discovery. This is critical for the zero-config promise — aftercowboy init dev or cowboy init local,
commands use the configured key and network without extra flags.

