# 发送 Bundle

用一个 HTTP/1.1 请求、以 JSON-RPC sendBundle 发送 1 到 4 笔已签名交易；它们要么按顺序原子化落地，要么全部不落地。

## 路由

| 路由 | 请求体 | 密钥 |
|---|---|---|
| `POST /v1/sendBundle` | JSON-RPC `sendBundle` | `api-key` 请求头 |

- 密钥与发送交易时所用的相同，放在 `api-key` 请求头中：见[身份验证](/docs/zh/tx-landing/http/#authentication)。
- 这是唯一的 bundle 路由。路径须完全一致且区分大小写。
- 端口 80 上的明文 HTTP/1.1：密钥以未加密方式传输。不提供 HTTPS 和 HTTP/2。
- Bundle 仅支持 HTTP。不通过 QUIC 提供 Bundle。

## 规则

- **仅限付费档位。** Free [档位](/docs/zh/tx-landing/rate-limits/#tiers)的密钥会得到 `403` `bundles require a paid tier`，不消耗 TPS 单位。
- **1 到 4 笔交易。** 每笔都已签名，且任意两笔的签名不同。
- **小费。** 其中一笔交易带至少 0.001 SOL (1,000,000 lamports) 的[小费](/docs/zh/tx-landing/endpoints/#tip-rule)，所有档位相同。多笔交易中的小费不会相加。更高的小费可获得更广的覆盖范围，从而带来更高的落地率。
- **速率限制。** 一个 bundle 无论大小都消耗 1 个 TPS 单位，与你的交易共用同一个[速率限制](/docs/zh/tx-landing/rate-limits/)。
- **大小限制。** 每笔交易最多 1232 字节（legacy、v0）或 4096 字节（v1）；请求体最多 32768 字节。

## sendBundle

请求的格式与 Jito 的 `sendBundle` 相同，交易为 base64。示例使用法兰克福；任何[端点](/docs/zh/tx-landing/endpoints/)均可使用。

**curl**

```sh
TX1_BASE64='<first signed transaction, base64>'
TX2_BASE64='<second signed transaction, base64>'

curl http://fra.landing.soyas.xyz/v1/sendBundle \
  -H "api-key: $SOYAS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"sendBundle","params":[["'"$TX1_BASE64"'","'"$TX2_BASE64"'"]]}'
```

**Python**

```python
import base64
import requests

session = requests.Session()  # keeps the connection open between requests

# txs: 1 to 4 signed transactions' wire bytes (solders: [bytes(tx1), bytes(tx2)]).
def send_bundle(api_key: str, txs: list[bytes]) -> list[str]:
    encoded = [base64.b64encode(tx).decode() for tx in txs]
    resp = session.post(
        "http://fra.landing.soyas.xyz/v1/sendBundle",
        headers={"api-key": api_key},
        json={
            "jsonrpc": "2.0",
            "id": 1,
            "method": "sendBundle",
            "params": [encoded],
        },
    )
    if resp.status_code != 200:
        raise RuntimeError(f"{resp.status_code}: {resp.text}")
    return resp.json()["result"]
```

**Go**

```go
import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"net/http"
)

// txs: 1 to 4 signed transactions' wire bytes (solana-go: tx.MarshalBinary()).
func sendBundle(apiKey string, txs [][]byte) ([]string, error) {
	encoded := make([]string, len(txs))
	for i, tx := range txs {
		encoded[i] = base64.StdEncoding.EncodeToString(tx)
	}
	body, _ := json.Marshal(map[string]any{
		"jsonrpc": "2.0",
		"id":      1,
		"method":  "sendBundle",
		"params":  []any{encoded},
	})
	req, _ := http.NewRequest("POST", "http://fra.landing.soyas.xyz/v1/sendBundle", bytes.NewReader(body))
	req.Header.Set("api-key", apiKey)
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	var out struct {
		Result []string        `json:"result"`
		Error  json.RawMessage `json:"error"`
	}
	if json.NewDecoder(resp.Body).Decode(&out); len(out.Result) == 0 {
		return nil, fmt.Errorf("%s: %s", resp.Status, out.Error)
	}
	return out.Result, nil
}
```

**Rust**

```rust
use base64::Engine as _;
use serde_json::{json, Value};
use solana_sdk::transaction::VersionedTransaction;

async fn send_bundle(
    http: &reqwest::Client,
    api_key: &str,
    txs: &[VersionedTransaction],
) -> anyhow::Result<Vec<String>> {
    let encoded: Vec<String> = txs
        .iter()
        .map(|tx| Ok(base64::engine::general_purpose::STANDARD.encode(bincode::serialize(tx)?)))
        .collect::<anyhow::Result<_>>()?;
    let resp = http
        .post("http://fra.landing.soyas.xyz/v1/sendBundle")
        .header("api-key", api_key)
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "sendBundle",
            "params": [encoded],
        }))
        .send()
        .await?;
    let status = resp.status();
    let body: Value = resp.json().await.unwrap_or_default();
    match serde_json::from_value(body["result"].clone()) {
        Ok(signatures) => Ok(signatures),
        Err(_) => anyhow::bail!("{status}: {body}"),
    }
}
```

- 交易使用 base64（标准字母表，带填充）；base58 会被拒绝。选项会被忽略。`id` 原样返回。
- 每个 HTTP 请求发送一个 bundle：JSON-RPC 批量请求（最外层为 JSON 数组）会被拒绝。
- `/v1/sendBundle` 只接受 `sendBundle`；其他所有 JSON-RPC 方法均应答 `400`，代码为 `-32601`。

## 应答

`200`，`Content-Type: application/json`：

```json
{"jsonrpc":"2.0","id":1,"result":["<signature 1>","<signature 2>"]}
```

- `result` 是每笔交易的第一个签名（base58），顺序与你发送的一致。
- 它表示中继接受了该 bundle，而不是它已落地。请在你自己的 RPC 节点上用 `getSignatureStatuses` 查询这些签名。
- 中继不验证签名、不做模拟，也不去重：同一个 bundle 发送两次会被转发两次并消耗 2 个 TPS 单位。

所有错误状态码和消息见[错误](/docs/zh/tx-landing/errors/)。除请求体外，连接限制和保持连接与[通过 HTTP 发送交易](/docs/zh/tx-landing/http/#limits)相同。
