> For the complete documentation index, see [llms.txt](https://node1.gitbook.io/node1-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://node1.gitbook.io/node1-docs/documentation/zh/solana/fast-landing/batch-api.md).

# 批量提交 API

一次请求最多提交 4 笔已签名的交易。它们作为一个 bundle 送达:按给定顺序执行、落在同一个区块、要么全部上链要么一笔都不上。任何一笔失败,整批都不会上链。适合不能被拆开的多步交易。

* 接口:`POST /v2/batch`,任一区域主机均可(`https://fra.node1.me/v2/batch`)
* 请求头:`api-key: $APIKEY`
* 请求体:原始字节,格式见下。不是 JSON,也不做 base64。
* 1 到 4 笔交易,每笔都是完整签名后的序列化交易(就是你调 `sendTransaction` 时拿去 base64 的那份字节),单笔最大 1232 字节(v1 交易 4096)。
* 小费:整批里转给 Node1 小费账户的金额加总,须达到你所在套餐的最低小费。小费放在其中任意一笔里都可以。
* 限速:一批按 1 次计入你的 TPS。

## 请求体格式

```
偏移        长度        字段
0           1           count            交易笔数,1..4
1           2 * count   lengths          每笔交易的长度,u16 小端,按顺序
1+2*count   sum(len)    transactions     各笔序列化交易按顺序拼接

请求体总长必须恰好等于 1 + 2*count + sum(lengths) 字节。
```

## 响应

HTTP 200,JSON,签名顺序与请求中的交易顺序一致:

```json
{"jsonrpc":"2.0","id":1,"result":["<第 0 笔的签名>","<第 1 笔的签名>"]}
```

其它情况都是错误。HTTP 状态码就是错误码,响应体是纯文本说明:

```
401   Invalid Api-Key / Not Found api-key        api-key 无效或缺失
429   Exceed Rate Limit: N per second            超过限速
605   Batch Decode Error: ...                    请求体格式不对,或某笔交易解析不了
606   Tip Instruction Not Found                  整批里没有转给 Node1 小费账户的交易
607   Please add a minimum tip of N lamports (batch total)   整批小费加总不足
```

## 示例:curl

请求体已先写到文件里。

```bash
curl -X POST "https://fra.node1.me/v2/batch" \
  -H "api-key: $APIKEY" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @batch.bin
```

## 示例:Rust

以下 Rust 片段需要由你的应用提供 `api_key` 与 `txs`。`txs` 为在本地签名并序列化后的交易；运行前请替换示例占位符。

```rust
// Cargo.toml: reqwest = { version = "0.12", features = ["blocking"] }
use reqwest::blocking::Client;

fn batch_body(txs: &[Vec<u8>]) -> Vec<u8> {
    let mut body = vec![txs.len() as u8];
    for tx in txs {
        body.extend_from_slice(&(tx.len() as u16).to_le_bytes());
    }
    for tx in txs {
        body.extend_from_slice(tx);
    }
    body
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 已签名的交易,按执行顺序排列
    // let txs = vec![bincode::serialize(&tx1)?, bincode::serialize(&tx2)?];
    let resp = Client::new()
        .post("https://fra.node1.me/v2/batch")
        .header("api-key", api_key)
        .body(batch_body(&txs))
        .send()?;
    println!("{} {}", resp.status(), resp.text()?);
    // 200 {"jsonrpc":"2.0","id":1,"result":["5oBk...","3SFd..."]}
    Ok(())
}
```


---

# 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, and the optional `goal` query parameter:

```
GET https://node1.gitbook.io/node1-docs/documentation/zh/solana/fast-landing/batch-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
