> For the complete documentation index, see [llms.txt](https://docs.baas.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.baas.sh/baas-sdk/blockchain/networks.md).

# Networks

The `baas.chains` namespace lets your users pick which network (EVM chain) is used for passkey sign-in. The list comes from your project's configuration, so it's always in sync across BaaS.

{% hint style="info" %}
This is **not** a wallet connector layer (use wagmi or RainbowKit for that). It's a small, opinionated wrapper around the chains your project exposes.
{% endhint %}

## Usage

```ts
const chains = await baas.chains.list();   // async — fetches /networks once, then memoized
// → [{ value: 'base', label: 'Base', chainId: 8453, rpcUrl: '…', isMainnet: true }, …]

baas.chains.active();   // → null until a chain is chosen, then the selected chain id

await baas.chains.switch(10);   // switch to Optimism

const unsubscribe = baas.chains.onChainChange((chainId) => {
  // chainId is `number | null`; fires immediately, then on every switch
});
```

| Method                                  | Description                                                                                |
| --------------------------------------- | ------------------------------------------------------------------------------------------ |
| `list(): Promise<readonly BaasChain[]>` | The chains your project supports, fetched once and then memoized.                          |
| `active(): number \| null`              | The selected chain id, or `null` if the user hasn't chosen one yet.                        |
| `switch(chainId): Promise<void>`        | Switch the active chain. Throws `UNKNOWN_CHAIN` if it isn't in `list()`.                   |
| `onChainChange(cb): () => void`         | Subscribe to changes. Fires immediately (with `number \| null`), then on every `switch()`. |

## The default chain

`active()` returns the selected chain id, or `null` if the user hasn't chosen one. While it's `null`, sign-in uses the **first network** in your project's list by default. The choice is saved in `localStorage` (scoped to your `projectId`) and survives page reloads.

## External wallets are unaffected

`baas.chains` only governs **passkey** sign-in. An external wallet carries its own chain selection, so `signInWithWallet()` ignores `baas.chains.switch()`.

{% hint style="warning" %}
**`baas.chains` is a preference, not a security boundary.** A user can edit `localStorage` (or bypass the SDK entirely) to sign on a different chain. This is intrinsic to any browser-side storage.

If your app must enforce a specific chain, call `await baas.chains.switch(<chainId>)` right after `createBaasClient()` to overwrite any local value at boot. This is a soft defense; real enforcement belongs on your BaaS API.
{% endhint %}

## Next

* [API reference](/baas-sdk/resources/api-reference.md) — the `BaasChain` type and full method signatures.
* [Error handling](/baas-sdk/resources/error-handling.md) — `UNKNOWN_CHAIN` and network errors from `list()` / `switch()`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.baas.sh/baas-sdk/blockchain/networks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
