nautechsystems/nautilus_trader · error

Blockchain address ' ' is incorrect

Error message

Blockchain address '{address}' is incorrect: {e}

What it means

validate_address parses an Ethereum address string into an alloy Address after checking the 0x prefix. This error wraps the low-level parse failure: the string has invalid length (must be 42 chars including 0x) or contains non-hexadecimal characters. The library throws it to surface malformed blockchain identifiers early instead of propagating them into pool or token state.

Solutions

  1. Ensure the address string is exactly 42 characters and starts with 0x.
  2. Strip surrounding whitespace/quotes and trim before validating.
  3. Verify the address source (config file, CSV, database) for truncation or encoding issues.
  4. Regenerate the address from a trusted source; a parse failure usually means a typo.

Example fix

// before
let addr = validate_address(raw_address.trim_matches('"'))?;
// after
let cleaned = raw_address.trim().trim_start_matches("\"").trim_end_matches("\"").to_lowercase();
if cleaned.len() != 42 || !cleaned.starts_with("0x") {
    anyhow::bail!("malformed address: {raw_address}");
}
let addr = validate_address(&cleaned)?;
Defensive patterns

Strategy: validation

Validate before calling

fn looks_like_eth_address(s: &str) -> bool {
    let s = s.trim();
    s.len() == 42 && s.starts_with("0x") && s[2..].chars().all(|c| c.is_ascii_hexdigit())
}

Type guard

fn parse_eth_address(s: &str) -> Option<alloy_primitives::Address> {
    alloy_primitives::Address::from_str(s.trim()).ok()
}

Try / catch

match validate_address(input.trim()) {
    Ok(addr) => addr,
    Err(e) if e.to_string().contains("is incorrect") => {
        tracing::warn!("malformed address in config: {input}");
        return Err(e);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling validate_address (or APIs that call it: PoolPosition construction, decode_address, multicall setup, subscribe handling) with a string that is not exactly '0x' + 40 hex characters, or contains invalid characters.

Common situations: Hardcoded addresses with typos; addresses truncated or pasted without the 0x prefix handled elsewhere; reading token addresses from a config/CSV with whitespace or quotes; mixing 20-byte binary data rendered as decimal.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/f611df9c0cd131fd. Report an issue: GitHub.

Appendix: source

Thrown at crates/model/src/defi/validation.rs:43

/// Validates an Ethereum address format, checksum, and returns the parsed address.
///
/// # Errors
///
/// This function returns an error if:
/// - The address does not start with the `0x` prefix.
/// - The address has invalid length (must be 42 characters including `0x`).
/// - The address contains invalid hexadecimal characters.
/// - The address has an incorrect checksum (for checksummed addresses).
pub fn validate_address(address: &str) -> anyhow::Result<Address> {
    // Check if the address starts with "0x"
    if !address.starts_with("0x") {
        anyhow::bail!("Ethereum address must start with '0x': {address}");
    }

    // Check if the address is valid
    let parsed_address = Address::from_str(address)
        .map_err(|e| anyhow::anyhow!("Blockchain address '{address}' is incorrect: {e}"))?;

    // Check if checksum is valid
    Address::parse_checksummed(address, None)
        .map_err(|_| anyhow::anyhow!("Blockchain address '{address}' has incorrect checksum"))?;

    Ok(parsed_address)
}

#[cfg(test)]
mod tests {
    use rstest::rstest;

    use super::*;

    #[rstest]
    fn test_validate_address_invalid_prefix() {
        let invalid_address = "742d35Cc6634C0532925a3b844Bc454e4438f44e";
        let result = validate_address(invalid_address);

View on GitHub (pinned to 18893faf8b)