QUIC
Send transactions over QUIC on UDP port 9000, one unidirectional stream per transaction.
| Setting | Value |
|---|---|
| Address | <host>:9000, UDP, from Endpoints |
| ALPN | solana-tpu |
| Server name | soyas-landing (the relay does not check it) |
| Client certificate | X.509, self-signed is fine, whose public key is your API key’s Ed25519 public key; handshake signed with Ed25519 |
| Server certificate | Self-signed; its DER SHA-256 is quic.tlsCertSha256 in endpoints.json. The relay does not require you to verify it. |
Your API key, from the dashboard, is never sent over QUIC: your client makes the certificate from it and signs the handshake with its secret key. The relay checks no certificate authority, only the key.
use anyhow::Context as _;use quinn::{crypto::rustls::QuicClientConfig, ClientConfig, Connection, Endpoint, IdleTimeout, TransportConfig};use solana_sdk::signature::Keypair;use solana_tls_utils::{new_dummy_x509_certificate, SkipServerVerification};use std::{net::ToSocketAddrs as _, sync::Arc, time::Duration};
const ALPN: &[u8] = b"solana-tpu";const SERVER_NAME: &str = "soyas-landing";const KEEP_ALIVE: Duration = Duration::from_secs(25);const IDLE_TIMEOUT: Duration = Duration::from_secs(30);
// addr: "fra.landing.soyas.xyz:9000". api_key: the base58 keypair from the dashboard.async fn connect(addr: &str, api_key: &str) -> anyhow::Result<Connection> { let _ = rustls::crypto::ring::default_provider().install_default(); // rustls needs one per process let (cert, key) = new_dummy_x509_certificate(&Keypair::from_base58_string(api_key)); let mut crypto = rustls::ClientConfig::builder() .dangerous() .with_custom_certificate_verifier(SkipServerVerification::new()) // the relay's certificate is self-signed .with_client_auth_cert(vec![cert], key)?; crypto.alpn_protocols = vec![ALPN.to_vec()];
let mut transport = TransportConfig::default(); transport.keep_alive_interval(Some(KEEP_ALIVE)); transport.max_idle_timeout(Some(IdleTimeout::try_from(IDLE_TIMEOUT)?)); let mut config = ClientConfig::new(Arc::new(QuicClientConfig::try_from(crypto)?)); config.transport_config(Arc::new(transport));
let mut endpoint = Endpoint::client("0.0.0.0:0".parse()?)?; endpoint.set_default_client_config(config); let addr = addr.to_socket_addrs()?.next().context("address not resolved")?; Ok(endpoint.connect(addr, SERVER_NAME)?.await?)}
// One stream per transaction. tx: its wire bytes (bincode::serialize(&tx)?).async fn send(conn: &Connection, tx: &[u8]) -> anyhow::Result<()> { let mut stream = conn.open_uni().await?; stream.write_all(tx).await?; stream.finish()?; Ok(())}import ( "context" "crypto/ed25519" "crypto/rand" "crypto/tls" "crypto/x509" "errors" "math/big" "time"
"github.com/mr-tron/base58" "github.com/quic-go/quic-go" // v0.48)
const ( alpn = "solana-tpu" serverName = "soyas-landing" keepAlive = 25 * time.Second idleTimeout = 30 * time.Second)
// addr: "fra.landing.soyas.xyz:9000". apiKey: the base58 keypair from the dashboard.func connect(ctx context.Context, addr, apiKey string) (quic.Connection, error) { raw, err := base58.Decode(apiKey) if err != nil || len(raw) != ed25519.PrivateKeySize { return nil, errors.New("the API key is not a base58 64-byte keypair") } key := ed25519.NewKeyFromSeed(raw[:ed25519.SeedSize]) template := &x509.Certificate{ SerialNumber: big.NewInt(1), NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(365 * 24 * time.Hour), } cert, err := x509.CreateCertificate(rand.Reader, template, template, key.Public(), key) if err != nil { return nil, err } return quic.DialAddr(ctx, addr, &tls.Config{ Certificates: []tls.Certificate{{Certificate: [][]byte{cert}, PrivateKey: key}}, NextProtos: []string{alpn}, ServerName: serverName, InsecureSkipVerify: true, // the relay's certificate is self-signed MinVersion: tls.VersionTLS13, }, &quic.Config{KeepAlivePeriod: keepAlive, MaxIdleTimeout: idleTimeout})}
// One stream per transaction. tx: its wire bytes (solana-go: tx.MarshalBinary()).func send(ctx context.Context, conn quic.Connection, tx []byte) error { stream, err := conn.OpenUniStreamSync(ctx) if err != nil { return err } if _, err := stream.Write(tx); err != nil { return err } return stream.Close()}import asyncioimport sslfrom contextlib import asynccontextmanagerfrom datetime import datetime, timedelta, timezone
import base58from aioquic.asyncio.client import connect as quic_connectfrom aioquic.quic.configuration import QuicConfigurationfrom cryptography import x509from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKeyfrom cryptography.x509.oid import NameOID
ALPN = "solana-tpu"SERVER_NAME = "soyas-landing"KEEP_ALIVE = 25.0IDLE_TIMEOUT = 30.0
# host: "fra.landing.soyas.xyz", port: 9000. api_key: the base58 keypair from the dashboard.# async with connect(host, port, api_key) as protocol: send(protocol, tx)@asynccontextmanagerasync def connect(host: str, port: int, api_key: str): key = Ed25519PrivateKey.from_private_bytes(base58.b58decode(api_key)[:32]) name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, "soyas-client")]) now = datetime.now(timezone.utc) config = QuicConfiguration( is_client=True, alpn_protocols=[ALPN], server_name=SERVER_NAME, verify_mode=ssl.CERT_NONE, # the relay's certificate is self-signed idle_timeout=IDLE_TIMEOUT, ) config.certificate = ( x509.CertificateBuilder() .subject_name(name) .issuer_name(name) .public_key(key.public_key()) .serial_number(x509.random_serial_number()) .not_valid_before(now - timedelta(hours=1)) .not_valid_after(now + timedelta(days=365)) .sign(key, None) ) config.private_key = key async with quic_connect(host, port, configuration=config) as protocol: pinging = asyncio.create_task(keep_alive(protocol)) try: yield protocol finally: pinging.cancel()
async def keep_alive(protocol): # aioquic has no keep-alive setting. while True: await asyncio.sleep(KEEP_ALIVE) await protocol.ping()
# One stream per transaction. tx: its wire bytes (solders: bytes(tx)).def send(protocol, tx: bytes) -> None: stream_id = protocol._quic.get_next_available_stream_id(is_unidirectional=True) protocol._quic.send_stream_data(stream_id, tx, end_stream=True) protocol.transmit()One stream carries one transaction in Solana’s wire format; the relay reads it to its end. Bidirectional streams are not allowed. One QUIC datagram also carries one transaction.
Open one persistent connection per endpoint and reuse it. Finish every stream you open: an unfinished stream has already used one transaction of your rate limit.
What the relay answers
Section titled “What the relay answers”Nothing: no acknowledgment, no signature, no error. A stream your client wrote and finished only means the bytes were handed to QUIC. For an answer per transaction, use HTTP.
| Case | What your client sees |
|---|---|
| Certificate key not Ed25519, or a bad handshake signature | The TLS handshake fails. |
| No client certificate, or a key the relay does not know | The handshake completes, then the connection is closed with application error code 0 and reason NotWhitelisted. |
| Too many open connections for your key | The oldest connection is closed with application error code 0 and reason TooManyConnections. |
| Key removed or disabled while connected | The connection stays open and every transaction on it is dropped; a restored key works again on the same connection. |
| Transaction empty, unparseable, without signature or signer, over a limit below, without a tip, or over your rate limit | Dropped, without a word. |
Limits and timeouts
Section titled “Limits and timeouts”| Limit | Value |
|---|---|
| Connection | Reuse one persistent connection per endpoint |
| Stream length | 8192 bytes |
| Legacy and v0 transaction | 1232 bytes |
| v1 transaction | 4096 bytes |
| Transactions per second | Your account’s rate limit, per endpoint, shared with HTTP; a stream counts when accepted, before it is read |
| Idle timeout | 30 s. The relay sends no keep-alives: send your own more often (the code above uses 25 s). |
