# resolve_network

> Return the CAIP-2 id for a network name or id, and register it with x402.

```python
from ai_economy_sdk import resolve_network
```

```python
def resolve_network(network: str, algod_client: Any = None) -> str
```

Return the CAIP-2 id for a network name or id, and register it with x402.

Resolves short aliases such as `"mainnet"` or `"testnet"` to canonical
short CAIP-2 identifiers (`"algorand:<32-char-prefix>"`). Normalizes legacy
long IDs (`"algorand:<44-char-hash>"`). When given `"localnet"` or its aliases,
queries the provided `algod_client` (or the default localnet endpoint) to
derive and register the network configuration dynamically.

## Parameters

- `network` (`str`, required):
Network name, alias, canonical short CAIP-2 ID, or legacy long ID.

- `algod_client` (`Any`, default `None`):
Pre-configured `algosdk.v2client.algod.AlgodClient` instance. Used
to query genesis parameters when resolving `"localnet"`.

## Returns

- `returns` (`str`):
Canonical short CAIP-2 network identifier (e.g. `"algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k"`).

## Raises

- `UnknownNetworkError`: (a `ValueError`) If the network name cannot be resolved or is invalid.

## Examples

```python
>>> from ai_economy_sdk.network import resolve_network, MAINNET, TESTNET
>>> resolve_network("mainnet") == MAINNET
True
>>> resolve_network("testnet") == TESTNET
True
>>> resolve_network("algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=") == MAINNET
True
```

## See also

- `endpoints_for`: Resolves connection endpoints for the network.
- `genesis_hash_for`: Returns the full 44-character base64 genesis hash.

Source: [ai_economy_sdk/network.py](https://github.com/x402-avm/ai-economy-sdk/blob/main/ai_economy_sdk/network.py#L126)

Source: https://x402-avm.github.io/reference/python/ai-economy-sdk/resolve-network
