nautechsystems/nautilus_trader · error
Signer private key in
Error message
Signer private key in '{}' is not a valid hex private key What it means
After trimming and stripping an optional 0x prefix, the signer key must decode into exactly 32 bytes via hex::decode_array::<32>. If the value contains non-hex characters or is not exactly 32 bytes, initialization fails with this error.
Solutions
- Set the env var to exactly 64 hex characters (optionally with a single 0x prefix), e.g. 0xabc...def (128/64 chars check).
- Remove surrounding quotes, newlines, or trailing whitespace from the stored secret.
- Confirm you are providing a raw secp256k1 private key, not a mnemonic phrase, JSON keystore, or base64 key.
- Validate locally: printf '%s' "$VAR" | grep -Eq '^(0x)?[0-9a-fA-F]{64}$' before launching.
Example fix
// before export SIGNER_KEY="0xabc123" // truncated, quoted // after export SIGNER_KEY=0xabc123...full-64-hex-chars... // unquoted, exactly 64 hex chars
Defensive patterns
Strategy: validation
Validate before calling
fn is_hex_key(s: &str) -> bool {
let t = s.trim().strip_prefix("0x").unwrap_or(s.trim());
t.len() == 64 && t.chars().all(|c| c.is_ascii_hexdigit())
} Type guard
fn valid_private_key_env(v: &str) -> bool { let t = v.trim().strip_prefix("0x").unwrap_or(v.trim()); t.len() == 64 && t.chars().all(|c| c.is_ascii_hexdigit()) } Try / catch
if !valid_private_key_env(&std::env::var("SIGNER_KEY")?) { eprintln!("SIGNER_KEY must be 64 hex chars, optional 0x"); } Prevention
- Store the key as raw 64-char hex without quotes or whitespace
- Never paste mnemonics or keystores where a raw hex key is expected
- Lint secrets format at injection time in CI/deploy scripts
- Trim and 0x-strip defensively before validation
When it happens
Trigger: hex::decode_array::<32>(encoded_key) errors — the env var value is not valid hex, has wrong length (not 64 hex chars after optional 0x), contains whitespace inside, or includes stray quotes.
Common situations: Copying a key wrapped in quotes from an export, pasting a truncated key, using a base64 or mnemonic seed phrase instead of a hex private key, or including '0x' twice or internal spaces.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Signer private key environment variable
- Signer private key in
- Cannot create sign doc
- Chain checkpoint hash must contain 32 hexadecimal bytes
- config_path must be in format 'module.path:ClassName', was
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/0d1729426685a568.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/blockchain/src/execution/client.rs:6178
)
} else {
None
};
// Load the signer key from the configured environment variable; the key is never
// logged, serialized, or stored in configuration
let private_key = Zeroizing::new(
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 encoded_key = private_key.trim();
let encoded_key = encoded_key.strip_prefix("0x").unwrap_or(encoded_key);
let key_bytes = Zeroizing::new(hex::decode_array::<32>(encoded_key).map_err(|_| {
anyhow::anyhow!(
"Signer private key in '{}' is not a valid hex private key",
self.config.signer_private_key_env
)
})?);
let signer = PrivateKeySigner::from_slice(&key_bytes[..]).map_err(|_| {
anyhow::anyhow!(
"Signer private key in '{}' is not a valid secp256k1 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 18893faf8b)