# SWQoS

Discover a live tip account, submit a signed transaction and check its outcome

Source: https://zerocopy.sh/docs/quickstart/swqos

Create a team and [SWQoS API key](/docs/api-keys) in the [console](https://console.zerocopy.sh).

Use your own Solana RPC provider for reads. Build and sign the transaction in
your application, then send the signed transaction to SWQoS. Never send your
wallet's private key.

## 1. Discover a tip account [#1-discover-a-tip-account]

Call [`getTipAccounts`](/docs/reference/json-rpc/tip-accounts) before constructing the
transaction. Use one of the returned addresses as the destination of a System transfer.
The set can change, so do not hard code it. To tip in USDC, USDT or WSOL instead, see
[Tip in tokens](/docs/swqos/tips#tip-in-tokens).

Set `SWQOS_API_KEY` to your key. Rust and Go use the
[example project](/docs/reference/json-rpc#example-project); TypeScript uses `fetch`.

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

#[tokio::main]
async fn main() -> Result<()> {
    let response = reqwest::Client::new()
        .post("https://sol.zerocopy.sh")
        .header("x-api-key", required("SWQOS_API_KEY")?)
        .json(&json!({ "jsonrpc": "2.0", "id": 1, "method": "getTipAccounts" }))
        .send()
        .await?;
    let status = response.status();
    let body = response.text().await?;
    let reply: Value = serde_json::from_str(&body)
        .map_err(|error| format!("HTTP {status}: {error}; body: {body}"))?;
    if !status.is_success() || reply.get("error").is_some_and(|error| !error.is_null()) {
        return Err(format!("HTTP {status}: {reply}").into());
    }
    println!("{}", serde_json::to_string_pretty(&reply)?);
    Ok(())
}
```

```go title="discover-tip-account/main.go" tab="Go" tab-group="language"
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"strings"

	swqos "swqos-examples"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	apiKey, err := swqos.Required("SWQOS_API_KEY")
	if err != nil {
		return err
	}
	request, err := http.NewRequest(http.MethodPost, "https://sol.zerocopy.sh",
		strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"getTipAccounts"}`))
	if err != nil {
		return err
	}
	request.Header.Set("x-api-key", apiKey)
	request.Header.Set("Content-Type", "application/json")
	response, err := http.DefaultClient.Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	var reply map[string]any
	if err := json.NewDecoder(response.Body).Decode(&reply); err != nil {
		return fmt.Errorf("HTTP %d: %w", response.StatusCode, err)
	}
	if response.StatusCode < 200 || response.StatusCode >= 300 || reply["error"] != nil {
		return fmt.Errorf("HTTP %d: %v", response.StatusCode, reply)
	}
	output, err := json.MarshalIndent(reply, "", "  ")
	if err != nil {
		return err
	}
	fmt.Println(string(output))
	return nil
}
```

```ts title="discover-tip-account.ts" tab="TypeScript" tab-group="language"
const apiKey = process.env.SWQOS_API_KEY
if (!apiKey) throw new Error('set SWQOS_API_KEY')

const response = await fetch('https://sol.zerocopy.sh', {
  method: 'POST',
  headers: { 'x-api-key': apiKey, 'content-type': 'application/json' },
  body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getTipAccounts' }),
})
const body = await response.text()
let reply: { error?: unknown }
try {
  reply = JSON.parse(body)
} catch {
  throw new Error(`HTTP ${response.status}: invalid JSON; body: ${body}`)
}
if (!response.ok || reply.error != null) {
  throw new Error(`HTTP ${response.status}: ${JSON.stringify(reply)}`)
}
console.log(JSON.stringify(reply, null, 2))

export {}
```

```sh title="Discover a live tip account" tab="cURL" tab-group="language"
curl --fail-with-body -sS 'https://sol.zerocopy.sh' \
  -H "x-api-key: $SWQOS_API_KEY" \
  -H 'content-type: application/json' \
  --data '{"jsonrpc":"2.0","id":1,"method":"getTipAccounts"}'
```

The [cached discovery helpers](/docs/swqos/tips#tip-account-helper) provide Rust, Go and
TypeScript versions for repeated submissions.

If the list is empty or the service returns `not_ready`, wait for a fresh list
before you send. A previously returned account may no longer accept tips.

## 2. Build and sign [#2-build-and-sign]

Using your Solana RPC provider and transaction builder:

1. Fetch a recent blockhash, or prepare the durable nonce your transaction uses.
2. Add your application's instructions and a tip transfer to a returned account.
3. Use at least the minimum configured for your key. A
   [missing tip reply](/docs/reference/errors#missing_tip) reports the required amount.
4. Sign with every required signer and serialize the completed transaction.

The tip is separate from Solana's transaction and priority fees. The transaction's fee
payer must be able to pay those fees. This quickstart uses a transfer inside the
transaction, not a [declared tip](/docs/account/billing#declared-tips).

## 3. Submit the signed transaction [#3-submit-the-signed-transaction]

Pass the signed transaction to `sendTransaction`. Rust and Go use the
[example project](/docs/reference/json-rpc#example-project).

```rust title="src/send_transaction.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_signed_transaction(
    api_key: &str,
    transaction: &VersionedTransaction,
) -> Result<String> {
    let wire = wincode::serialize(transaction)?;
    request(
        "https://sol.zerocopy.sh",
        Some(api_key),
        "sendTransaction",
        Some(json!([
            BASE64_STANDARD.encode(wire),
            { "encoding": "base64", "skipPreflight": true }
        ])),
    )
    .await
}
```

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

import (
	"context"
	"encoding/base64"

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

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

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

export async function sendSignedTransaction(apiKey: string, transaction: Transaction) {
  const rpc = createSolanaRpc('https://sol.zerocopy.sh', {
    headers: { 'x-api-key': apiKey },
  })
  return rpc.sendTransaction(getBase64EncodedWireTransaction(transaction), {
    encoding: 'base64',
    skipPreflight: true,
  }).send()
}
```

The response contains the transaction's first signature. Use it to check whether
the transaction landed. These examples use base64 encoding and skip simulation. See the
[`sendTransaction` reference](/docs/reference/json-rpc/send-transaction) for all options.

For structured refusals, read `error.data` from the HTTP response as shown in the
[JSON-RPC examples](/docs/reference/json-rpc). Solana kit can throw on an HTTP error before
exposing the body, and its error code mapping does not preserve every SWQoS `reason`.

## 4. Check the outcome [#4-check-the-outcome]

Use your Solana RPC provider's `getSignatureStatuses` or transaction subscription to
check the returned signature. Do not call read methods on the SWQoS send endpoint.

Confirm at the commitment your application needs. The
[confirmation example](/docs/swqos/confirmation#confirmation) accepts `confirmed` or `finalized`.

An accepted send can fail to land or execute with an error. SWQoS does not resubmit
automatically. Check the original signature before replacing an expired transaction
or advancing a nonce. See [confirmation and retries](/docs/swqos/confirmation).

For ordered groups of up to four transactions, use [bundles](/docs/swqos/bundles).
For rejected requests, use the structured `reason` and `retryable` fields in the
[error reference](/docs/reference/errors).
