> For the complete documentation index, see [llms.txt](https://docs.squidrouter.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.squidrouter.exchange/api-and-sdk-integration/sdk/chains-tokens-balances.md).

# Chains, Tokens & Prices

The Squid SDK provides utility methods for querying chain configurations, token data, and prices. These methods are available after calling `squid.init()`.

## Setup

```typescript
import { Squid } from "@0xsquid/sdk";

const squid = new Squid({
  baseUrl: "https://v2.api.squidrouter.exchange",
  integratorId: "your-integrator-id",
});

await squid.init();

// After init(), these properties are populated:
console.log(squid.chains.length);  // e.g. 92 supported chains
console.log(squid.tokens.length);  // e.g. 9689 supported tokens
```

***

## Chain Data

### `squid.chains`

After `init()`, the `chains` property contains an array of all supported chains.

### `squid.getChainData(chainId)`

Look up a specific chain by its chain ID.

```typescript
const chain = squid.getChainData("42161");
```

**Returns:**

```json
{
  "chainId": "42161",
  "chainName": "Chain 42161",
  "networkName": "Arbitrum",
  "chainType": "evm",
  "nativeCurrency": {
    "name": "Arbitrum",
    "symbol": "ETH",
    "decimals": 18,
    "icon": "https://..."
  },
  "squidContracts": {
    "squidRouter": "0xce16F69375520ab01377ce7B88f5BA8C48F8D666"
  }
}
```

| Field            | Type     | Description                                                                          |
| ---------------- | -------- | ------------------------------------------------------------------------------------ |
| `chainId`        | `string` | Chain identifier                                                                     |
| `chainName`      | `string` | Internal chain name                                                                  |
| `networkName`    | `string` | Human-readable network name (e.g. `"Arbitrum"`, `"Ethereum"`)                        |
| `chainType`      | `string` | Chain ecosystem: `"evm"`, `"cosmos"`, `"solana"`, `"bitcoin"`, `"xrpl"`, `"stellar"` |
| `nativeCurrency` | `object` | Native token details (name, symbol, decimals, icon)                                  |
| `squidContracts` | `object` | Squid contract addresses on this chain (e.g. `squidRouter`)                          |

***

## Token Data

### `squid.tokens`

After `init()`, the `tokens` property contains an array of all supported tokens across all chains.

### `squid.getTokenData(address, chainId)`

Look up a specific token by its address and chain ID.

```typescript
const token = squid.getTokenData("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "1");
```

**Returns:**

```json
{
  "symbol": "USDC",
  "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
  "chainId": "1",
  "name": "USDC",
  "decimals": 6,
  "coingeckoId": "usd-coin",
  "type": "evm",
  "logoURI": "https://...",
  "usdPrice": 0.9996
}
```

| Field         | Type     | Description                            |
| ------------- | -------- | -------------------------------------- |
| `symbol`      | `string` | Token symbol                           |
| `address`     | `string` | Token contract address                 |
| `chainId`     | `string` | Chain ID                               |
| `name`        | `string` | Full token name                        |
| `decimals`    | `number` | Token decimal places                   |
| `coingeckoId` | `string` | CoinGecko identifier for price lookups |
| `type`        | `string` | Chain type (e.g. `"evm"`)              |
| `logoURI`     | `string` | Token logo URL                         |
| `usdPrice`    | `number` | Current USD price                      |

***

## Token Prices

### `squid.getTokenPrice({ tokenAddress, chainId })`

Get the current USD price for a single token.

```typescript
const price = await squid.getTokenPrice({
  tokenAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
  chainId: "1",
});
// Returns: 0.9996203987960182 (number)
```

**Returns:** `number` — The current USD price of the token.

### `squid.getMultipleTokensPrice({ chainId? })`

Get all tokens with their current USD prices, optionally filtered by chain ID.

```typescript
// Get prices for all tokens on Arbitrum
const tokens = await squid.getMultipleTokensPrice({ chainId: "42161" });

tokens.forEach(token => {
  console.log(`${token.symbol}: $${token.usdPrice}`);
});
```

**Returns:** `Token[]` — An array of token objects, each including a `usdPrice` field.

### `squid.getFromAmount({ fromToken, toToken, toAmount })`

Estimate how much of a source token is needed to receive a specific amount of a destination token. Useful for "exact output" UIs.

```typescript
const fromAmount = await squid.getFromAmount({
  fromToken: squid.getTokenData("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "1"),
  toToken: squid.getTokenData("0xaf88d065e77c8cc2239327c5edb3a432268e5831", "42161"),
  toAmount: "1000000", // 1 USDC (6 decimals)
});
// Returns: "1015000" (string — ~1.015 USDC needed, accounting for fees)
```

**Returns:** `string` — The estimated source amount in the token's smallest unit.

***

## Token Approval

### `squid.isRouteApproved({ route, sender })`

Check if the sender has approved the Squid router to spend the required source token amount.

```typescript
const { isApproved, message } = await squid.isRouteApproved({
  route: routeResponse.route,
  sender: "0x...",
});

if (!isApproved) {
  console.log(message); // Describes what approval is needed
}
```

### `squid.approveRoute({ signer, route })`

Approve the Squid router to spend the source token. Required before executing ERC-20 swaps.

```typescript
const tx = await squid.approveRoute({
  signer, // ethers.js Signer
  route: routeResponse.route,
});

if (tx) {
  await tx.wait(); // Wait for approval to be mined
}
```


---

# 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.squidrouter.exchange/api-and-sdk-integration/sdk/chains-tokens-balances.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.
