Send raw bytes
Send a signed transaction or bundle as raw payload bytes over HTTP, with an optional declared tip.
x-api-key<token>Send the SWQoS API key in this header. See the authentication reference for compatibility forms and precedence.
One signed transaction or a payload envelope with a declared tip or bundle. Maximum body 16,403 bytes, received within 2 seconds. There is no encoding option or preflight simulation. The same tip, send rate and transaction rules apply as for JSON-RPC. Uses the same hosts, ports and authentication as JSON-RPC.
body*fileapplication/octet-streamRaw payload bytes. A signed transaction or an envelope with a declared tip or bundle; the payload envelope defines the binary layout shared with QUIC streams and IPC records.
binaryReturns the transaction's first signature in base58 or the bundle ID as 64 hex characters, in plain text. Acceptance does not mean landing; confirm signatures through your Solana RPC provider.
response?stringtext/plainBase58 transaction signature or 64-character hex bundle id.
// Builds on the example project (/reference/json-rpc#example-project).
use swqos_examples::{
payload::bundle_payload,
swqos::{Result, required, url},
};
#[tokio::main]
async fn main() -> Result<()> {
// Signed transaction files, in bundle order.
let mut transactions = Vec::new();
for file in std::env::args().skip(1) {
transactions.push(tokio::fs::read(file).await?);
}
let response = reqwest::Client::new()
.post(format!("{}/binary", url()))
.header("x-api-key", required("SWQOS_API_KEY")?)
.body(bundle_payload(&transactions, None)?)
.send()
.await?;
let status = response.status();
let body = response.text().await?;
if status.is_success() {
println!("bundle {body}");
} else {
println!("refused {}: {body}", status.as_u16());
}
Ok(())
}Rust (payload encoder)
// Builds on the example project (/reference/json-rpc#example-project).
// src/payload.rs
use crate::swqos::Result;
pub fn transaction_payload(transaction: &[u8], declared_tip: Option<u64>) -> Vec<u8> {
let mut payload = Vec::with_capacity(
transaction.len() + usize::from(declared_tip.is_some()) * 10,
);
if let Some(tip) = declared_tip {
payload.extend_from_slice(&[0x00, 0x01]);
payload.extend_from_slice(&tip.to_le_bytes());
}
payload.extend_from_slice(transaction);
payload
}
pub fn bundle_payload(
transactions: &[Vec<u8>],
declared_tip: Option<u64>,
) -> Result<Vec<u8>> {
if !(1..=4).contains(&transactions.len()) {
return Err("a bundle holds 1 to 4 transactions".into());
}
let size = 3
+ usize::from(declared_tip.is_some()) * 8
+ transactions
.iter()
.map(|transaction| 2 + transaction.len())
.sum::<usize>();
let mut payload = Vec::with_capacity(size);
payload
.extend_from_slice(&[0x00, if declared_tip.is_some() { 0x03 } else { 0x02 }]);
if let Some(tip) = declared_tip {
payload.extend_from_slice(&tip.to_le_bytes());
}
payload.push(transactions.len() as u8);
for transaction in transactions {
payload.extend_from_slice(&(transaction.len() as u16).to_le_bytes());
payload.extend_from_slice(transaction);
}
Ok(payload)
}BASE58_SIGNATURE