# Local interfaces

Connect HTTP, QUIC or IPC clients to the local agent and handle replies and failures

Source: https://zerocopy.sh/docs/swqos/agent/local-interfaces

Choose an interface after [installing and starting the agent](/docs/swqos/agent/install-and-run).

| Interface | Address in these examples | Configuration |
| --- | --- | --- |
| HTTP and JSON-RPC | `http://127.0.0.1:8080` | `listen.http` |
| QUIC | UDP `127.0.0.1:4433` | `listen.quic` |
| Shared memory IPC | `/run/zerocopy/agent.sock` | `listen.ipc` |

## Protect local access [#authentication]

Local requests use the executable's license. API key headers, query parameters and QUIC client certificates do not authenticate callers. Keep network listeners on loopback and restrict IPC socket access: anyone who can reach a listener can submit transactions and incur charges on your account.

## HTTP and JSON-RPC [#http]

Point your client at `http://127.0.0.1:8080`, or your configured `listen.http` address. Use the hosted [JSON-RPC](/docs/reference/json-rpc) and [HTTP](/docs/reference/http) request formats.

### Reuse connections [#connection]

The listener supports HTTP/1.1 and cleartext HTTP/2. HTTP/1.1 connections close after 60 idle seconds; reconnect as needed. The agent does not apply the hosted HTTP connection limit per source IP.

### Choose a method or route [#methods]

Use `sendTransaction` for one transaction or `sendBundle` for an ordered group. Fetch current tip accounts, or token accounts for [token tips](#token-tips), locally before constructing a transaction. Use a hosted endpoint for the tip floor and a separate Solana RPC provider for chain state.

The [local method reference](/docs/reference/json-rpc#local-agent) defines query replies and the differences from hosted requests.

### Request preflight [#preflight]

Set `skipPreflight: false` to request simulation. Check the [local preflight rules](/docs/reference/json-rpc#local-agent) before choosing simulation options.

### Query the tip floor remotely [#tip-floor]

Call [`getTipFloor`](/docs/reference/json-rpc/tip-floor) on a hosted endpoint with your [API key](/docs/api-keys).

### Tip in tokens or through lookup tables [#token-tips]

Fetch token accounts locally with `getTipTokenAccounts`. It returns the same entries as the [hosted method](/docs/reference/json-rpc/tip-token-accounts), and an empty array before the agent receives routing information.

The agent checks SOL tips to static account keys itself. When that SOL tip is below your key's minimum and the transaction also carries a [token tip](/docs/swqos/tips#tip-in-tokens) to a listed token account, or a tip transfer whose recipient comes from an [address lookup table](/docs/swqos/tips#lookup-tables), the agent has the region value the tip first. It sends to leaders directly only after the region accepts, which adds the region's round trip. A send without a reply goes through the region only. Bundles always go through the region.

The agent relays the region's refusal unchanged, such as `missing_tip`, or `not_ready` with `waiting_for: token_price` or `lookup_table`. Agent releases that predate token tips refuse these transactions locally with `missing_tip`; the agent updates automatically.

### Send through local HTTP [#examples]

Fetch the current tip accounts:

```rust title="src/bin/local_tip_accounts.rs" tab="Rust" tab-group="language"
use swqos_examples::swqos::{Result, request};

#[tokio::main]
async fn main() -> Result<()> {
    let accounts: Vec<String> =
        request("http://127.0.0.1:8080", None, "getTipAccounts", None).await?;
    println!("{}", serde_json::to_string(&accounts)?);
    Ok(())
}
```

```go title="local-tip-accounts/main.go" tab="Go" tab-group="language"
package main

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

func main() {
	if err := run(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}

func run() error {
	body := []byte(`{"jsonrpc":"2.0","id":1,"method":"getTipAccounts"}`)
	response, err := http.Post("http://127.0.0.1:8080", "application/json", bytes.NewReader(body))
	if err != nil {
		return err
	}
	defer response.Body.Close()
	reply, err := io.ReadAll(response.Body)
	if err != nil {
		return err
	}
	var result struct {
		Result []string        `json:"result"`
		Error  json.RawMessage `json:"error"`
	}
	if err := json.Unmarshal(reply, &result); err != nil {
		return err
	}
	if response.StatusCode != http.StatusOK || len(result.Error) != 0 {
		return fmt.Errorf("HTTP %d: %s", response.StatusCode, reply)
	}
	return json.NewEncoder(os.Stdout).Encode(result.Result)
}
```

```ts title="local-tip-accounts.ts" tab="TypeScript" tab-group="language"
const response = await fetch('http://127.0.0.1:8080', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getTipAccounts' }),
})
const reply = (await response.json()) as { result: string[]; error?: unknown }
if (!response.ok || reply.error) {
  throw new Error(`HTTP ${response.status}: ${JSON.stringify(reply)}`)
}
console.log(JSON.stringify(reply.result))
export {}
```

```sh title="Fetch current tip accounts" tab="cURL" tab-group="language"
curl -sS http://127.0.0.1:8080 \
  -H 'content-type: application/json' \
  --data '{"jsonrpc":"2.0","id":1,"method":"getTipAccounts"}'
```

Set `TX_BASE64` to a signed transaction encoded as base64 with a [qualifying tip](/docs/swqos/tips). The result is its first signature.

```rust title="src/bin/local_send_transaction.rs" tab="Rust" tab-group="language"
use serde_json::json;
use swqos_examples::swqos::{Result, request, required};

#[tokio::main]
async fn main() -> Result<()> {
    let signature: String = request(
        "http://127.0.0.1:8080",
        None,
        "sendTransaction",
        Some(json!([required("TX_BASE64")?, { "encoding": "base64" }])),
    )
    .await?;
    println!("{signature}");
    Ok(())
}
```

```go title="local-send-transaction/main.go" tab="Go" tab-group="language"
package main

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

func main() {
	if err := run(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}

func run() error {
	transaction := os.Getenv("TX_BASE64")
	if transaction == "" {
		return fmt.Errorf("set TX_BASE64")
	}
	body, err := json.Marshal(map[string]any{
		"jsonrpc": "2.0", "id": 1, "method": "sendTransaction",
		"params": []any{transaction, map[string]any{"encoding": "base64"}},
	})
	if err != nil {
		return err
	}
	response, err := http.Post("http://127.0.0.1:8080", "application/json", bytes.NewReader(body))
	if err != nil {
		return err
	}
	defer response.Body.Close()
	reply, err := io.ReadAll(response.Body)
	if err != nil {
		return err
	}
	var result struct {
		Result string          `json:"result"`
		Error  json.RawMessage `json:"error"`
	}
	if err := json.Unmarshal(reply, &result); err != nil {
		return err
	}
	if response.StatusCode != http.StatusOK || len(result.Error) != 0 {
		return fmt.Errorf("HTTP %d: %s", response.StatusCode, reply)
	}
	fmt.Println(result.Result)
	return nil
}
```

```ts title="local-send-transaction.ts" tab="TypeScript" tab-group="language"
const transaction = process.env.TX_BASE64
if (!transaction) throw new Error('set TX_BASE64')
const response = await fetch('http://127.0.0.1:8080', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'sendTransaction',
    params: [transaction, { encoding: 'base64' }],
  }),
})
const reply = (await response.json()) as { result: string; error?: unknown }
if (!response.ok || reply.error) {
  throw new Error(`HTTP ${response.status}: ${JSON.stringify(reply)}`)
}
console.log(reply.result)
export {}
```

```sh title="Send a signed transaction" tab="cURL" tab-group="language"
curl -sS http://127.0.0.1:8080 \
  -H 'content-type: application/json' \
  --data "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"sendTransaction\",\"params\":[\"$TX_BASE64\",{\"encoding\":\"base64\"}]}"
```

These functions take a transaction your application has already signed:

```rust title="src/send_through_agent.rs" tab="Rust" tab-group="language"
use base64::{Engine, prelude::BASE64_STANDARD};
use serde_json::json;
use solana_transaction::versioned::VersionedTransaction;

use crate::swqos::{Result, request};

pub async fn send_through_agent(transaction: &VersionedTransaction) -> Result<String> {
    request(
        "http://127.0.0.1:8080",
        None,
        "sendTransaction",
        Some(json!([
            BASE64_STANDARD.encode(wincode::serialize(transaction)?),
            { "encoding": "base64", "skipPreflight": true }
        ])),
    )
    .await
}
```

```go title="send_through_agent.go" tab="Go" tab-group="language"
package swqos

import (
	"context"
	"encoding/base64"

	"github.com/gagliardetto/solana-go"
)

func SendThroughAgent(ctx context.Context, transaction *solana.Transaction) (string, error) {
	wire, err := transaction.MarshalBinary()
	if err != nil {
		return "", err
	}
	return callAt[string](ctx, "http://127.0.0.1:8080", "", "sendTransaction",
		base64.StdEncoding.EncodeToString(wire),
		map[string]any{"encoding": "base64", "skipPreflight": true},
	)
}
```

```ts title="send-through-agent.ts" tab="TypeScript" tab-group="language"
import {
  createSolanaRpc,
  getBase64EncodedWireTransaction,
  type Transaction,
} from '@solana/kit'

const agent = createSolanaRpc('http://127.0.0.1:8080')

export async function sendThroughAgent(transaction: Transaction) {
  return agent
    .sendTransaction(getBase64EncodedWireTransaction(transaction), {
      encoding: 'base64',
      skipPreflight: true,
    })
    .send()
}
```

Fetch blockhashes and check outcomes with your separate Solana RPC provider.

## QUIC [#quic]

Connect to UDP `127.0.0.1:4433`, or your configured `listen.quic` address. Use the hosted [QUIC payloads and replies](/docs/reference/quic) with the local connection settings below.

### Connection settings [#settings]

Use the [local QUIC connection settings](/docs/reference/quic#local-agent). Send keep alive pings to hold a quiet connection open.

### Accept the local certificate [#certificate]

Use `localhost` as the server name and configure your client to accept the agent's changing self signed certificate. If your library requires disabling certificate verification, restrict that exception to the loopback listener. Keep verification enabled for hosted endpoints.

### Choose streams with replies [#sending]

Use bidirectional streams for a transaction or bundle when you need acceptance and rejection details. Transaction preflight runs at `processed` commitment. Unidirectional streams carry transactions or bundles without replies; a refusal drops the submission without notice. Use replies while integrating.

Follow the [QUIC reference](/docs/reference/quic#streams) for stream kinds, flags and framing, and its [reply codes](/docs/reference/quic#reply-codes) for decoding results. Local acceptance and rejection guidance below applies to those replies.

## IPC [#ipc]

Use IPC to submit through shared memory on the same Linux host. The [Rust, Go and TypeScript clients](/docs/reference/ipc#example) send one transaction, request a reply, wait up to five seconds and exit. They do not construct or sign the transaction. The standalone C client is also available.

### Prepare the client [#requirements]

Run the agent with an explicit `listen.ipc` path. Give your application account [socket access](/docs/swqos/agent/install-and-run#ipc-access), then restart the application after any group change.

Prepare a signed transaction with a valid blockhash and the required tip. Fetch current tip accounts through the agent's `getTipAccounts` method.

### Download and build the example [#example]

For Rust, Go or TypeScript, use the [complete IPC clients and runtime requirements](/docs/reference/ipc#example). They implement the handshake and ring protocol described there. To use the C client instead:

<a href="/docs/examples/swqos-ipc-send.c" download>Download swqos-ipc-send.c</a>

Build it on Linux x86_64 with GCC or Clang:

```sh title="Build the IPC example"
cc -std=c11 -O2 -Wall -Wextra -o swqos-ipc-send swqos-ipc-send.c
```

### Connect and submit [#handshake]

Save the signed transaction's raw wire bytes in a file. If you have base64 text, decode it first:

```sh title="Submit signed bytes over IPC"
base64 --decode signed-transaction.b64 > signed-transaction.bin
./swqos-ipc-send /run/zerocopy/agent.sock signed-transaction.bin
```

Use your configured socket path if it differs. Run as an account with socket access.

### Send other submissions [#submissions]

The example requests a reply without preflight. Custom clients can send bundles, request transaction preflight or declare a tip. Arrange [declared tips](/docs/swqos/tips#declared-tips) with support before using them.

Follow the [IPC submission reference](/docs/reference/ipc#submissions) and [payload envelope reference](/docs/reference/payload-envelope) for record kinds, flags and payloads. Request replies while integrating so your client can report refusals.

### Read the reply [#completions]

An accepted transaction prints:

```text
code 0
```

The example exits with status 0 only for an accepted reply. For a refusal, it prints a nonzero [reply code](/docs/reference/quic#reply-codes) and any JSON error detail, then exits with status 1. Use the detail's `reason` to find the cause in [Errors](/docs/reference/errors).

Long running clients must keep draining completions, match them by request ID rather than arrival order and set a timeout for every request.

### Reconnect after a restart [#errors]

An agent stop or [automatic update](/docs/swqos/agent/operations#restart) closes the IPC session. Open a new socket and repeat the handshake. Do not reuse an old mapping or automatically replay requests with unknown outcomes.

For connection failures and missing completions, see [operations troubleshooting](/docs/swqos/agent/operations#clients). Custom clients must follow the [record and ring rules](/docs/reference/ipc#writing).

## Interpret acceptance [#accepted]

An accepted reply means the agent accepted the request for forwarding. Check its signature through your Solana RPC provider to determine whether it landed.

The agent does not keep resubmitting after it answers. A timeout, disconnection or rejection can leave the outcome uncertain. Failover may send the same bytes more than once. Check the signature before sending a replacement; see [Confirmation](/docs/swqos/confirmation).

## Handle rejections [#rejections]

Rejections use the shared [error format](/docs/reference/errors).

| Reason | Action |
| --- | --- |
| [`missing_tip`](/docs/reference/errors#missing_tip) | Meet your key's minimum with a current tip account, token account or enabled declaration |
| [`not_ready`](/docs/reference/errors#not_ready), `waiting_for: tip_vaults` | Fetch tip accounts again shortly |
| [`not_ready`](/docs/reference/errors#not_ready), `waiting_for: token_price` or `lookup_table` | Retry shortly, or tip in SOL to a static tip account |
| [`not_ready`](/docs/reference/errors#not_ready), `waiting_for: upstream` | Check network access and service logs |
| [`forward_failed`](/docs/reference/errors#forward_failed) | Check the signature before retrying |

The agent may already have sent a transaction directly to a leader when an edge refuses it. A rejection does not prove that the transaction was never forwarded.
