> ## Documentation Index
> Fetch the complete documentation index at: https://docs.caldera.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Utilities

> SDK utility functions for common operations

## Utility Functions

The SDK provides utility functions for common operations:

### `chainToViemChain(chain)`

Convert a Metalayer [Chain](/metalayer/sdk/api-reference#chain) object to Viem chain format. Use the result as your **wagmi `chains`** list and pass the same viem `Chain` values into **`@metalayer/widget`** helpers such as [`createWidgetTransport`](/metalayer/widget/components#createwidgettransport-chain), [`createWidgetClient`](/metalayer/widget/components#createwidgetclient-chain), and [`createWidgetTransportsRecord`](/metalayer/widget/components#createwidgettransportsrecord-chains) (see [Widget Components](/metalayer/widget/components#rpc-transport-helpers)).

```typescript theme={null}
import { chainToViemChain } from '@metalayer/sdk';

const viemChain = chainToViemChain(chain);
```

### `chainsToViemChains(chains)`

Convert an array of Metalayer [Chain](/metalayer/sdk/api-reference#chain) objects to an array of Viem chains. Invalid or non-EVM chains are filtered out. The returned array is suitable for wagmi and for the widget transport helpers linked above.

```typescript theme={null}
import { chainsToViemChains } from '@metalayer/sdk';

const viemChains = chainsToViemChains(chains);
```

### `collectChainHttpRpcUrls(chain)`

Collects unique **HTTP** RPC URLs from a viem `Chain` produced by **`chainToViemChain`**, in Metalayer order: URLs under **`rpcUrls.default`**, then alternate slots **`rpc-0`**, **`rpc-1`**, … (sorted by index), which map to **`alternativeRpcs`** from the Metalayer chain. Used internally by **`createWidgetTransport`** in `@metalayer/widget`; you can use it directly when building custom viem **`fallback()`** stacks or other transports.

```typescript theme={null}
import { collectChainHttpRpcUrls } from '@metalayer/sdk';

const urls = collectChainHttpRpcUrls(viemChain);
```

### `formatQuoteProvider(provider)`

Format a [QuoteProvider](/metalayer/sdk/api-reference#quoteprovider) enum value to a readable string.

```typescript theme={null}
import { formatQuoteProvider, QuoteProvider } from '@metalayer/sdk';

const name = formatQuoteProvider(QuoteProvider.ACROSS); // "Across"
```
