nautechsystems/nautilus_trader · critical · anyhow::Error
Signer private key environment variable '{}' is not set
Error message
Signer private key environment variable '{}' is not set What it means
During connect (client.rs:2775) the signer key is read from the environment variable named by config.signer_private_key_env. This error means that variable is not set in the process environment. The key is deliberately never stored in configuration, so a missing env var stops connect before any signature is attempted.
Source
Thrown at crates/adapters/blockchain/src/execution/client.rs:2777
} else {
log::warn!(
"No Postgres cache database configured; transactions will be refused (no durable store)"
);
}
// Verify the RPC chain ID against configuration before any signature
let expected_chain_id = u64::from(self.chain.chain_id);
let actual_chain_id = self.http_rpc_client.chain_id().await?;
if actual_chain_id != expected_chain_id {
anyhow::bail!(
"Chain ID mismatch at connect: expected {expected_chain_id}, node reported {actual_chain_id}"
);
}
// Load the signer key from the configured environment variable; the key is never
// logged, serialized, or stored in configuration
let private_key = std::env::var(&self.config.signer_private_key_env).map_err(|_| {
anyhow::anyhow!(
"Signer private key environment variable '{}' is not set",
self.config.signer_private_key_env
)
})?;
let signer = PrivateKeySigner::from_str(private_key.trim()).map_err(|_| {
anyhow::anyhow!(
"Signer private key in '{}' is not a valid hex private key",
self.config.signer_private_key_env
)
})?;
if signer.address() != self.wallet_address {
anyhow::bail!(
"Signer address {} derived from '{}' does not match configured wallet address {}",
signer.address(),
self.config.signer_private_key_env,
self.wallet_address
);View on GitHub (pinned to 2114cf6f76)
Solutions
- Check the exact name in the error message and verify with printenv / env | grep <NAME> in the same context the process runs.
- Export or inject the variable into the service environment (secret manager, systemd Environment=, compose env_file).
- Never place the key value in config files; keep the config pointing at the variable name.
- Add a startup preflight that fails fast with a clear message if the variable is absent.
Example fix
# before export PRIVATE_KEY=... # but config expects SIGNER_KEY # after # signer_private_key_env = "SIGNER_KEY" export SIGNER_KEY=0x... # 32-byte hex private key
Defensive patterns
Strategy: validation
Validate before calling
// startup preflight:
let key = std::env::var(&config.signer_private_key_env)
.unwrap_or_else(|_| panic!("env var '{}' must be set before start", config.signer_private_key_env)); Type guard
fn signer_env_is_set(name: &str) -> bool { std::env::var(name).is_ok() } Try / catch
Fail startup immediately with the variable name; no retry is useful until the environment is fixed.
Prevention
- Inject secrets via the platform's secret mechanism (systemd Environment=, compose env_file, k8s secrets).
- Add a deployment checklist item verifying the signer variable in the exact runtime context.
When it happens
Trigger: Running under systemd/docker/k8s where the variable was not injected into the unit/compose/pod spec; the variable name in signer_private_key_env does not match what was exported (case-sensitive); the var set in an interactive shell but not in the service environment.
Common situations: Deploying to a new environment without replicating secrets; renaming the env var in config without updating the secret store; CI runs lacking the secret.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Signer private key in '{}' is not a valid hex private key
- {standard_key_var} not found in config or environment
- {standard_secret_var} not found in config or environment
- Failed to create HTTP client: {e}
- Timeout waiting for account {account_id} to be registered af
AI-assisted analysis of nautechsystems/nautilus_trader@2114cf6f76 (2026-08-21).
Data as JSON: /api/errors/d4ee9ea9d1f004f1.
Report an issue: GitHub.