> ## 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.

# Client Methods

> Metalayer SDK client methods for cross-chain operations

# `MetalayerClient.init(config)`

Create an instance of the Metalayer SDK client with your configuration.

### MetalayerConfig

| Property         | Type                                      | Description                                      | Default                             | Required |
| ---------------- | ----------------------------------------- | ------------------------------------------------ | ----------------------------------- | -------- |
| `apiKey`         | `string`                                  | Your application's API key for the Metalayer API | -                                   | ✅        |
| `environment`    | `'mainnet' \| 'testnet'`                  | The environment to use.                          | `'mainnet'`                         | ✅        |
| `defaultOptions` | **[MetalayerOptions](#metalayeroptions)** | Default options for the Metalayer client         | `{ quotePreference: 'bestReturn' }` | ❌        |
| `customApiUrl`   | `string`                                  | Override the default API URL for the environment | `undefined`                         | ❌        |

```typescript theme={null}
const client = MetalayerClient.init({
  apiKey: 'your-api-key',
  environment: 'mainnet',
  defaultOptions: {
    quotePreference: 'fastest',
    chainIds: [1, 33139, 42161], // Filter for Ethereum Mainnet, ApeChain, Arbitrum One
  },
});
```

### MetalayerOptions

| Property          | Type                        | Description                                                                                                                                          | Default        | Required |
| ----------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------- |
| `quotePreference` | `'bestReturn' \| 'fastest'` | Quote optimization preference for routing                                                                                                            | `'bestReturn'` | ❌        |
| `chainIds`        | `number[]`                  | Default chain IDs for internal filtering in `getSupportedChains()`, `getTokens()`, and `getOrders()` methods. Can be overridden by method parameters | `undefined`    | ❌        |

# `client.getSupportedChains(params?)`

Get supported blockchain networks.

### Parameters

| Property   | Type       | Description                                                                                                                                                       | Default                             | Required |
| ---------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | -------- |
| `chainIds` | `number[]` | List of chain IDs to filter. Defaults to all chains or SDK config `chainIds` if not provided. The response will return chain metadata for all chains in this list | SDK config `chainIds` or all chains | ❌        |

```typescript theme={null}
// Get all supported chains
const { chains } = await client.getSupportedChains();

// Get specific chains only
const { chains } = await client.getSupportedChains({
  chainIds: [1, 33139, 42161] // Ethereum Mainnet, ApeChain, Arbitrum One
});
```

### Response

| Property | Type                                               | Description                                                   |
| -------- | -------------------------------------------------- | ------------------------------------------------------------- |
| `chains` | **[Chain](/metalayer/sdk/api-reference#chain)\[]** | List of blockchain networks supported for cross-chain routing |

# `client.getTokens(params?)`

Get token information by chain.

### Parameters

| Property   | Type       | Description                                                                                                       | Default                             | Required |
| ---------- | ---------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------- | -------- |
| `chainIds` | `number[]` | Filters tokens by chain ID presence in this list. Defaults to all chains or SDK config `chainIds` if not provided | SDK config `chainIds` or all chains | ❌        |

```typescript theme={null}
// Get tokens for all supported chains
const { tokensByChain } = await client.getTokens();

// Get tokens for specific chains
const { tokensByChain } = await client.getTokens({
  chainIds: [1, 33139, 42161] // Ethereum Mainnet, ApeChain, Arbitrum One
});
```

### Response

| Property        | Type                                                                        | Description                                            |
| --------------- | --------------------------------------------------------------------------- | ------------------------------------------------------ |
| `tokensByChain` | `Record<number, `**[TokenList](/metalayer/sdk/api-reference#tokenlist)**`>` | Mapping of chain ID to available tokens for that chain |

# `client.quote(params)`

Get quotes for cross-chain bridging.

### Parameters

| Property                  | Type                        | Description                                                                                               | Default         | Required                    |
| ------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------- | --------------- | --------------------------- |
| `sourceChainId`           | `number`                    | Source chain ID                                                                                           | -               | ✅                           |
| `sourceTokenAddress`      | `string`                    | Source token address                                                                                      | -               | ✅                           |
| `destinationChainId`      | `number`                    | Destination chain ID                                                                                      | -               | ✅                           |
| `destinationTokenAddress` | `string`                    | Destination token address                                                                                 | -               | ✅                           |
| `amount`                  | `BigInt`                    | Amount to swap                                                                                            | -               | ✅                           |
| `senderAddress`           | `string`                    | Sender wallet address                                                                                     | -               | ✅                           |
| `receiverAddress`         | `string`                    | Receiver wallet address. Required when bridging between different architectures (e.g., Ethereum → Solana) | `senderAddress` | ❌ (✅ if cross-architecture) |
| `quotePreference`         | `'bestReturn' \| 'fastest'` | Quote optimization preference                                                                             | `'bestReturn'`  | ❌                           |

```typescript theme={null}
const response = await client.quote({
  sourceChainId: 1,
  sourceTokenAddress: '0x0000000000000000000000000000000000000000',
  destinationChainId: 33139,
  destinationTokenAddress: '0x0000000000000000000000000000000000000000',
  amount: BigInt('1000000000000000000'),
  senderAddress: '0xYourAddress',
});
```

### Response

| Property           | Type                                                                | Description                                 |
| ------------------ | ------------------------------------------------------------------- | ------------------------------------------- |
| `sourceChain`      | **[ChainIdentifier](/metalayer/sdk/api-reference#chainidentifier)** | Source chain information                    |
| `destinationChain` | **[ChainIdentifier](/metalayer/sdk/api-reference#chainidentifier)** | Destination chain information               |
| `sourceToken`      | **[Token](/metalayer/sdk/api-reference#token)**                     | Source token information                    |
| `destinationToken` | **[Token](/metalayer/sdk/api-reference#token)**                     | Destination token information               |
| `quotes`           | **[Quote](/metalayer/sdk/api-reference#quote)\[]**                  | Array of quotes sorted by `quotePreference` |

# `client.getOrder(params)`

Get order details for a specific transaction.

### Parameters

| Property                | Type     | Description      | Default | Required |
| ----------------------- | -------- | ---------------- | ------- | -------- |
| `sourceTransactionHash` | `string` | Transaction hash | -       | ✅        |
| `sourceChainId`         | `number` | Source chain ID  | -       | ✅        |

```typescript theme={null}
const response = await client.getOrder({
  sourceTransactionHash: '0xTxHash',
  sourceChainId: 1,
});
```

### Response

| Property | Type                                            | Description                               |
| -------- | ----------------------------------------------- | ----------------------------------------- |
| `order`  | **[Order](/metalayer/sdk/api-reference#order)** | The order matching the request identifier |

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

const { order } = await client.getOrder({
  sourceTransactionHash: '0xTxHash',
  sourceChainId: 1,
});

// Check specific status
if (order.status === OrderStatus.FULFILLED) {
  console.log('Bridge transaction completed!');
}
```

# `client.getOrders(params)`

Returns a list of orders for a wallet address.

### Parameters

| Property   | Type       | Description                                                                                                  | Default                             | Required |
| ---------- | ---------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------------- | -------- |
| `address`  | `string`   | Wallet address to get orders for                                                                             | -                                   | ✅        |
| `chainIds` | `number[]` | List of chain IDs to filter the orders from. Defaults to all chains or SDK config `chainIds` if not provided | SDK config `chainIds` or all chains | ❌        |

```typescript theme={null}
// Get all orders for a wallet
const response = await client.getOrders({
  address: '0xWalletAddress',
});

// Get orders filtered by specific chains
const response = await client.getOrders({
  address: '0xWalletAddress',
  chainIds: [1, 33139, 42161], // Ethereum Mainnet, Ape Chain, Arbitrum One
});
```

### Response

| Property | Type                                                                | Description                                            |
| -------- | ------------------------------------------------------------------- | ------------------------------------------------------ |
| `orders` | **[Order](/metalayer/sdk/api-reference#order)\[]**                  | List of orders for the requested address               |
| `tokens` | `Record<string, `**[Token](/metalayer/sdk/api-reference#token)**`>` | Token metadata indexed by "chainId\_tokenAddress" keys |
