进阶

库与集成

BoltTx 就是一个简单的 REST API —— 任何语言的任何 HTTP 客户端都能用。无需 SDK,无需构建步骤,不被绑定。

为什么不提供 SDK?

我们的 API 只有三个字段:签名交易和两个简单选项。把这种东西包成 SDK 只会引入一个毫无收益的依赖 —— 使用语言原生的 HTTP 客户端反而更可靠、打包更小、不被版本绑定。

JavaScript / TypeScript

Native fetch

兼容 Node.js 18+、Deno、Bun 及所有现代浏览器。零依赖。

// Using the native fetch API (no SDK needed)
const res = await fetch("https://bolttx.io/v1/send", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    transaction: signedTxBase64,
    options: {
      skip_preflight: true,
      max_retries: 3,
      anti_mev: true,
    },
  }),
});

const { signature, slot } = await res.json();
console.log("Signature:", signature);

Python

requests

使用标准的 requests 库。适用于任何 Python 3.7+ 环境。

import requests

res = requests.post(
    "https://bolttx.io/v1/send",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
    },
    json={
        "transaction": signed_tx_base64,
        "options": {
            "skip_preflight": True,
            "max_retries": 3,
            "anti_mev": True,
        },
    },
)

data = res.json()
print(f"Signature: {data['signature']}")

Rust

reqwest

基于 Tokio 的生产级异步 HTTP 客户端。在 Cargo.toml 中添加 reqwest 即可。

use reqwest::Client;
use serde_json::json;

let client = Client::new();
let res = client
    .post("https://bolttx.io/v1/send")
    .bearer_auth("YOUR_API_KEY")
    .json(&json!({
        "transaction": signed_tx_base64,
        "options": {
            "skip_preflight": true,
            "max_retries": 3,
            "anti_mev": true,
        },
    }))
    .send()
    .await?
    .json::<serde_json::Value>()
    .await?;

println!("Signature: {}", res["signature"]);

Go

net/http

仅使用标准库,无外部依赖。

package main

import (
    "bytes"
    "encoding/json"
    "io"
    "net/http"
)

payload, _ := json.Marshal(map[string]interface{}{
    "transaction": signedTxBase64,
    "options": map[string]interface{}{
        "skip_preflight": true,
        "max_retries":    3,
        "anti_mev":       true,
    },
})

req, _ := http.NewRequest("POST", "https://bolttx.io/v1/send", bytes.NewBuffer(payload))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")

resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()

body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))

Solana 客户端库

已经在用 Solana 客户端(例如 @solana/web3.js, solana-py solana-client)?可以把它们直接指向 BoltTx 的 RPC 代理端点 无缝接入 —— 无需改动任何代码。

// @solana/web3.js — just swap the URL
const connection = new Connection(
  "https://bolttx.io/?api-key=YOUR_API_KEY"
);
await connection.sendRawTransaction(signedTx.serialize());