nautechsystems/nautilus_trader · error · anyhow::Error

Invalid chain ID: {s}

Error message

Invalid chain ID: {s}

What it means

dYdX adapter chain IDs are restricted to a closed set parsed from strings. `DydxCurrency/ChainId::from_str` only accepts `dydx-testnet-4`/`testnet` and `dydx-mainnet-1`/`mainnet`; any other chain identifier string is rejected with this error.

Source

Thrown at crates/adapters/dydx/src/grpc/types.rs:47

pub enum ChainId {
    /// Testnet.
    #[strum(serialize = "dydx-testnet-4")]
    #[serde(rename = "dydx-testnet-4")]
    Testnet4,
    /// Mainnet.
    #[strum(serialize = "dydx-mainnet-1")]
    #[serde(rename = "dydx-mainnet-1")]
    Mainnet1,
}

impl FromStr for ChainId {
    type Err = anyhow::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "dydx-testnet-4" | "testnet" => Ok(Self::Testnet4),
            "dydx-mainnet-1" | "mainnet" => Ok(Self::Mainnet1),
            _ => anyhow::bail!("Invalid chain ID: {s}"),
        }
    }
}

impl TryFrom<ChainId> for Id {
    type Error = Error;

    fn try_from(chain_id: ChainId) -> Result<Self, Self::Error> {
        chain_id.as_ref().parse()
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use one of the accepted values: `dydx-testnet-4`, `testnet`, `dydx-mainnet-1`, or `mainnet`
  2. Trim whitespace and fix casing of the configured chain ID string
  3. Check the dYdX adapter docs for currently supported networks and update config accordingly

Example fix

// before
let chain = DydxCurrency::from_str("dydx-testnet-3")?;
// after
let chain = DydxCurrency::from_str("dydx-testnet-4")?;
Defensive patterns

Strategy: validation

Validate before calling

const CHAIN_IDS: [&str; 4] = ["dydx-testnet-4", "testnet", "dydx-mainnet-1", "mainnet"];
fn is_valid_chain_id(s: &str) -> bool { CHAIN_IDS.contains(&s.trim()) }

Prevention

When it happens

Trigger: Passing any chain ID string other than the four accepted aliases into `DydxCurrency::from_str` (or config/env code that calls it), e.g. `"dydx-testnet-3"`, `"mainnet-1"`, or a fully-qualified Cosmos chain name like `"dydx-mainnet-1"` with different casing or whitespace.

Common situations: Reusing a chain ID from another Cosmos ecosystem (Osmosis, Cosmos Hub) or an older dYdX testnet (v3/v4-testnet variants); trailing spaces or wrong case in config files; hardcoding a chain name copied from dYdX v3 documentation.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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