> 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/udp-api.md).

# UDP API

向 node1域名:16888 发一个 UDP 数据包 = 一笔交易。无握手、无连接、无任何返回。

> 注册账号会自动生成 Account UUID，并开通 2 TPS 的 Solana 交易上链服务。可直接将该 UUID 作为本文的 API key；如需更高 TPS，请前往 Discord 申请。

## 包体

| 偏移 | 长度      | 字段       | 值 / 说明                              |
| -- | ------- | -------- | ----------------------------------- |
| 0  | 4       | magic    | 固定 \[43, 6, 58, 10]                 |
| 4  | 1       | method   | 0                                   |
| 5  | 16      | api\_key | 你的 API-key(UUID)的 16 字节,标准 UUID 字节序 |
| 21 | 2       | tx\_len  | u16 小端(little-endian)= tx 字节数       |
| 23 | tx\_len | tx       | 序列化的 Solana 交易                      |

总长 = 23 + tx\_len 字节,作为一个 UDP 包发出。

## 规则

* tx\_len 不要超过 1232(一笔完整 Solana 交易);超出会被拒。
* 无结果返回(fire-and-forget),服务端不回任何响应。是否上链请用交易签名自行到链上确认。
* 一个 UDP 包只放一笔交易。
* 包不合法、或超过你 API-key 的速率上限,会被静默丢弃(因为无返回,你不会收到错误)。
* 域名只在启动时解析一次(示例里的 connect\_node1),热路径只 send();不要把域名字符串传给 send\_to —— 每次发送都会做一次 DNS 解析(实测毫秒级),撑爆微秒级延迟。

## Rust 示例

```rust
use std::net::{ToSocketAddrs, UdpSocket};
use uuid::Uuid;

const MAGIC: [u8; 4] = [43, 6, 58, 10];

fn connect_node1(server: &str) -> std::io::Result<UdpSocket> {
    let addr = server
        .to_socket_addrs()?
        .next()
        .ok_or_else(|| std::io::Error::new(std::io::ErrorKind::NotFound, "DNS 解析为空"))?;
    let sock = UdpSocket::bind("0.0.0.0:0")?;
    sock.connect(addr)?;
    Ok(sock)
}

fn send_tx(sock: &UdpSocket, api_key: &Uuid, tx_bytes: &[u8]) -> std::io::Result<()> {
    assert!((1..=1232).contains(&tx_bytes.len()), "tx_len must be 1..=1232");
    let mut pkt = Vec::with_capacity(23 + tx_bytes.len());
    pkt.extend_from_slice(&MAGIC);                                  // magic[4]
    pkt.push(0);                                                    // method = 0
    pkt.extend_from_slice(api_key.as_bytes());                     // api_key[16]
    pkt.extend_from_slice(&(tx_bytes.len() as u16).to_le_bytes());  // tx_len[2] 小端
    pkt.extend_from_slice(tx_bytes);                               // tx[tx_len]
    sock.send(&pkt)?;                                              // fire-and-forget,已 connect 直接 send
    Ok(())
}

fn main() -> std::io::Result<()> {
    let sock = connect_node1("fra.node1.me:16888")?;  // 启动解析一次;换成你拿到的 node1 接入域名
    let api_key = Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap(); // 你的 API-key
    let tx_bytes: Vec<u8> = todo!("序列化的交易");
    send_tx(&sock, &api_key, &tx_bytes)?;
    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/udp-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.
