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

# Solana 地址查找表：用 RPC 查找 LUT

> 按 authority、账户或 mint 查找 Solana 地址查找表，为交易选择合适的表，并查看账户覆盖情况和预估节省的字节数。

地址查找表让 Solana 交易可以通过表索引引用账户。使用 Ridge RPC 方法查找包含交易账户的表，并在构建消息前选定要用的表。

* 某个钱包 authority 拥有的 LUT。
* 包含某个账户或代币 mint 的 LUT。
* 包含一组账户中全部账户的 LUT。
* 尽力选出的一组 LUT，用于缩小交易体积。

> [!NOTE]
>
> 每个 Lookup Table RPC 方法每次调用消耗 **1 积分**。

## 何时使用这些方法

在构建版本化交易之前使用这些方法，或用它们查看某个账户出现在哪些现有的表中。

| 目标 | 方法 |
| - | - |
| 查看钱包控制的 LUT | [`getLookupTablesByAuthority`](https://docs.solanatracker.io/cn/solana-rpc/http/getlookuptablesbyauthority) |
| 查找包含某个账户的 LUT | [`getLookupTablesByAccount`](https://docs.solanatracker.io/cn/solana-rpc/http/getlookuptablesbyaccount) |
| 查找包含某个代币 mint 的 LUT | [`getLookupTablesByMint`](https://docs.solanatracker.io/cn/solana-rpc/http/getlookuptablesbymint) |
| 查找覆盖多个账户的 LUT | [`getLookupTablesByAccounts`](https://docs.solanatracker.io/cn/solana-rpc/http/getlookuptablesbyaccounts) |

> [!TIP]
>
> 目标是优化交易时，先用 `getLookupTablesByAccounts`。想了解某个账户或 mint 出现在哪里时，再用单账户方法。

## RPC 端点

所有示例都通过 HTTP 使用 JSON-RPC 2.0：

```bash theme={null}
https://rpc-mainnet.solanatracker.io/?api_key=YOUR_API_KEY
```

## 按 authority 查找 LUT

用 `getLookupTablesByAuthority` 查询某个钱包 authority 控制的表。

```bash cURL theme={null}
curl "https://rpc-mainnet.solanatracker.io/?api_key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getLookupTablesByAuthority",
    "params": [{
      "authority": "WalletPubkey...",
      "limit": 100,
      "cursor": null,
      "mintsOnly": false,
      "includeDeactivated": false
    }]
  }'
```

```javascript JavaScript theme={null}
const rpcUrl = "https://rpc-mainnet.solanatracker.io/?api_key=YOUR_API_KEY";

const res = await fetch(rpcUrl, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getLookupTablesByAuthority",
    params: [{
      authority: "WalletPubkey...",
      limit: 100,
      cursor: null,
      mintsOnly: false,
      includeDeactivated: false
    }]
  })
});

const { result } = await res.json();

for (const lut of result.lookupTables) {
  console.log(`${lut.pubkey}: ${lut.addressCount} addresses`);
}
```

响应是分页的：

```json theme={null}
{
  "lookupTables": [
    {
      "pubkey": "LUTPubkey...",
      "authority": "WalletPubkey...",
      "deactivationSlot": 18446744073709551615,
      "addressCount": 12,
      "addresses": ["Account1...", "Account2..."],
      "mints": ["Mint1..."],
      "slot": 423867852
    }
  ],
  "nextCursor": "LUTPubkey...",
  "hasMore": false,
  "count": 1
}
```

`deactivationSlot` 为 `18446744073709551615` 表示 LUT 处于激活状态。

## 查找包含某个账户的 LUT

已知交易中会用到某个账户，想找到包含它的 LUT 时，使用 `getLookupTablesByAccount`。

```bash theme={null}
curl "https://rpc-mainnet.solanatracker.io/?api_key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getLookupTablesByAccount",
    "params": [{
      "account": "SomeAccountPubkey...",
      "owner": null,
      "limit": 100,
      "cursor": null
    }]
  }'
```

匹配结果包含用于交易优化的元数据：

| 字段 | 含义 |
| - | - |
| `addressIndex` | 匹配账户在 LUT 中的位置 |
| `matchedAccounts` | 查询的账户中在此 LUT 里找到的账户 |
| `matchedAddressIndices` | 匹配账户在 LUT 中的索引 |
| `estimatedBytesSaved` | 通过 LUT 引用匹配账户预计节省的字节数 |

## 查找包含某个 mint 的 LUT

`getLookupTablesByMint` 的查询方式与 `getLookupTablesByAccount` 相同，只是参数名为 `mint`。

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getLookupTablesByMint",
  "params": [{
    "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "limit": 100
  }]
}
```

交易围绕某个代币，想找到已包含该 mint 地址的 LUT 时使用。

## 为完整账户集查找 LUT

`getLookupTablesByAccounts` 有两种模式：交集模式和最佳集合模式。

### 交集模式

交集模式返回包含你提供的**每一个**账户的 LUT。需要一张表覆盖全部账户时使用。

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getLookupTablesByAccounts",
  "params": [{
    "accounts": ["AccountA...", "AccountB..."],
    "owner": null,
    "limit": 100,
    "cursor": null
  }]
}
```

### 最佳集合模式

最佳集合模式选择若干张表来覆盖传入的账户，以减小交易消息体积。

设置 `bestSet: true`，并传入交易需要的完整账户列表：

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getLookupTablesByAccounts",
  "params": [{
    "accounts": ["AccountA...", "AccountB...", "AccountC..."],
    "bestSet": true,
    "maxLookupTables": 8,
    "candidateLimit": 5000,
    "perAccountLimit": 500
  }]
}
```

响应会说明所选 LUT 覆盖了哪些账户：

```json theme={null}
{
  "lookupTables": [
    {
      "pubkey": "LUT1...",
      "matchedAccounts": ["AccountA...", "AccountB..."],
      "matchedAddressIndices": [3, 17],
      "estimatedBytesSaved": 62
    }
  ],
  "coveredAccounts": ["AccountA...", "AccountB..."],
  "uncoveredAccounts": ["AccountC..."],
  "estimatedBytesSaved": 62,
  "count": 1
}
```

### 最佳集合调优

| 参数 | 默认值 | 适用情况 |
| - | - | - |
| `maxLookupTables` | `8` | 想限制交易使用的 LUT 数量 |
| `candidateLimit` | `5000` | 需要限制考虑的候选表总数 |
| `perAccountLimit` | `500` | 某个账户出现在太多 LUT 中，导致候选搜索范围过大 |

先用默认值。测量返回的覆盖率、预估节省量和请求耗时后再调整。

## 示例：构建交易前选择 LUT

典型流程如下：

1. 收集交易会引用的账户。
2. 调用 `getLookupTablesByAccounts` 并设置 `bestSet: true`。
3. 把返回的 LUT 附加到交易构建器。
4. `uncoveredAccounts` 仍作为普通账户键。

```javascript theme={null}
const accounts = [
  "AccountA...",
  "AccountB...",
  "AccountC..."
];

const { result } = await fetch(
  "https://rpc-mainnet.solanatracker.io/?api_key=YOUR_API_KEY",
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      jsonrpc: "2.0",
      id: 1,
      method: "getLookupTablesByAccounts",
      params: [{
        accounts,
        bestSet: true,
        maxLookupTables: 8
      }]
    })
  }
).then(r => r.json());

console.log("Use LUTs:", result.lookupTables.map(lut => lut.pubkey));
console.log("Covered:", result.coveredAccounts);
console.log("Still inline:", result.uncoveredAccounts);
console.log("Estimated bytes saved:", result.estimatedBytesSaved);
```

## 实用建议

* `bestSet: true` 用于优化交易体积，不适合做穷举式发现。
* 只信任或只关心某个 authority 控制的 LUT 时，使用 `owner`。
* 构建面向代币的体验且不需要全部已存地址时，在 authority 查询中使用 `mintsOnly`。
* `estimatedBytesSaved` 只用于规划参考，最终交易仍要模拟。
* authority、账户和 mint 搜索都要保留分页逻辑。热门账户可能出现在很多 LUT 中。

> [card] [getLookupTablesByAccounts](https://docs.solanatracker.io/cn/solana-rpc/http/getlookuptablesbyaccounts.md)
>
> 查找覆盖多个账户的 LUT，或获取最合适的 LUT 集合。

> [card] [积分与限流](https://docs.solanatracker.io/cn/solana-rpc/credits-and-rate-limits.md)
>
> 查看 RPC 调用的积分消耗和套餐限制。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.