# Confirmation and retries

Check execution and commitment through your Solana RPC before deciding whether to resubmit

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

## What acceptance means [#acceptance]

A successful submission acknowledges only acceptance for delivery:

| Submission | Acknowledgment means |
| --- | --- |
| Hosted single transaction | SWQoS accepted the transaction for delivery |
| Hosted bundle | SWQoS accepted the bundle for delivery |
| Local agent | The agent accepted the request under its [local acceptance rules](/docs/swqos/agent/local-interfaces#accepted) |
| QUIC unidirectional stream or IPC without a reply | No acknowledgment exists |

None of these proves the signature is valid, the transaction can execute, an engine accepted it, or it landed. A submitted transaction can land successfully, land with an execution error, expire, or belong to a fork your chosen commitment does not retain.

## Routing [#routing]

See [Routing](/docs/swqos/routing) for leader delivery and block engine delivery. Bundles use block engines only. A response does not identify which path was used or which copy will land.

## No periodic resubmission [#no-resend]

SWQoS does not periodically resend accepted transactions or bundles. `maxRetries` is ignored. Your application owns confirmation and later resubmission.

### Duplicate suppression [#duplicates]

A recently repeated single transaction signature may be accepted without being sent again.
A repeat that arrives while the first is still being processed returns `rate_limited` without `per_second` or `retry_after_ms`.

Do not rely on this as global idempotency. Explicit bundle resubmissions are not suppressed, even though they return the same bundle id.

## Confirm through your Solana RPC [#confirmation]

Keep the first signature of each signed transaction before you send. Poll `getSignatureStatuses`, or subscribe to signature notifications, on your read RPC provider. Check both the execution error and the commitment. `getSlot` on SWQoS is not a confirmation check.

For a transaction using a recent blockhash, retain the `lastValidBlockHeight` returned with the blockhash used to sign it. If the chain passes that height and no landing is recorded, the transaction cannot newly execute with that blockhash. Rebuild and sign with a fresh blockhash only after checking the original outcome. A durable nonce has a different lifetime: check the nonce account and original signature before advancing or replacing it.

For a bundle, check every member's signature. SWQoS has no bundle status API, and its bundle id is not an engine's status id. If you sent members separately, seeing one on chain does not tell you which submission path delivered it.

```rust title="src/confirm.rs" tab="Rust" tab-group="language"
use std::time::Duration;

use serde::Deserialize;
use serde_json::{Value, json};
use solana_signature::Signature;

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

#[derive(Deserialize)]
struct Statuses {
    value: Vec<Option<Status>>,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct Status {
    err: Option<Value>,
    confirmation_status: Option<String>,
}

pub async fn wait_for_confirmation(
    rpc_url: &str,
    signature: &Signature,
    last_valid_block_height: u64,
) -> Result<()> {
    loop {
        let statuses: Statuses = request(
            rpc_url,
            None,
            "getSignatureStatuses",
            Some(
                json!([[signature.to_string()], { "searchTransactionHistory": true }]),
            ),
        )
        .await?;
        let status = statuses.value.first().and_then(Option::as_ref);
        if let Some(error) = status.and_then(|status| status.err.as_ref()) {
            return Err(format!("transaction failed: {error}").into());
        }
        if matches!(
            status.and_then(|status| status.confirmation_status.as_deref()),
            Some("confirmed" | "finalized")
        ) {
            return Ok(());
        }
        let height: u64 = request(
            rpc_url,
            None,
            "getBlockHeight",
            Some(json!([{ "commitment": "confirmed" }])),
        )
        .await?;
        if status.is_none() && height > last_valid_block_height {
            return Err("blockhash expired with no recorded landing".into());
        }
        tokio::time::sleep(Duration::from_millis(500)).await;
    }
}
```

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

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"time"

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

type confirmationStatus struct {
	Err                json.RawMessage `json:"err"`
	ConfirmationStatus string          `json:"confirmationStatus"`
}

func WaitForConfirmation(ctx context.Context, rpcURL string, signature solana.Signature, lastValidBlockHeight uint64) error {
	for {
		reply, err := callAt[struct {
			Value []*confirmationStatus `json:"value"`
		}](ctx, rpcURL, "", "getSignatureStatuses", []solana.Signature{signature},
			map[string]any{"searchTransactionHistory": true})
		if err != nil {
			return err
		}
		var status *confirmationStatus
		if len(reply.Value) > 0 {
			status = reply.Value[0]
		}
		if status != nil {
			if len(status.Err) > 0 && string(status.Err) != "null" {
				return fmt.Errorf("transaction failed: %s", status.Err)
			}
			if status.ConfirmationStatus == "confirmed" || status.ConfirmationStatus == "finalized" {
				return nil
			}
		}
		height, err := callAt[uint64](ctx, rpcURL, "", "getBlockHeight",
			map[string]any{"commitment": "confirmed"})
		if err != nil {
			return err
		}
		if status == nil && height > lastValidBlockHeight {
			return errors.New("blockhash expired with no recorded landing")
		}
		timer := time.NewTimer(500 * time.Millisecond)
		select {
		case <-ctx.Done():
			timer.Stop()
			return ctx.Err()
		case <-timer.C:
		}
	}
}
```

```ts title="confirm.ts" tab="TypeScript" tab-group="language"
import { setTimeout as sleep } from 'node:timers/promises'
import { createSolanaRpc, type Signature } from '@solana/kit'

export async function waitForConfirmation(
  rpcUrl: string,
  signature: Signature,
  lastValidBlockHeight: bigint,
): Promise<void> {
  const rpc = createSolanaRpc(rpcUrl)
  for (;;) {
    const { value: [status] } = await rpc
      .getSignatureStatuses([signature], { searchTransactionHistory: true })
      .send()
    if (status?.err) throw new Error(`transaction failed: ${JSON.stringify(status.err)}`)
    if (status?.confirmationStatus === 'confirmed' || status?.confirmationStatus === 'finalized') {
      return
    }
    const height = await rpc.getBlockHeight({ commitment: 'confirmed' }).send()
    if (!status && height > lastValidBlockHeight) {
      throw new Error('blockhash expired with no recorded landing')
    }
    await sleep(500)
  }
}
```

Pass the signature and last valid height from the transaction you actually signed. This example waits for `confirmed` or `finalized` and does not resend.

## Decide whether to retry [#retry]

| Situation | Action |
| --- | --- |
| Structured refusal with `retryable: true` | Resubmit unchanged after `retry_after_ms` when supplied, while the signed lifetime remains valid. |
| Structured refusal with `retryable: false` | Fix the cause or settle the invoice. A blind retry does not fix the request. |
| Accepted, but not yet confirmed | Check the signature and lifetime. You may resubmit the same signed bytes while valid; a duplicate at the same edge may be suppressed. |
| Timeout or lost connection before a reply | The request may already have been sent. Check the signature before deciding to resubmit. |
| Local agent rejection | A direct leader write may have happened before the edge refused it. Follow the [local rejection rules](/docs/swqos/agent/local-interfaces#rejections). |
| Expired recent blockhash | Check the original outcome, then rebuild and sign again if your application still needs the action. |

Resubmissions can consume rate allowance. Solana prevents the same signed transaction from executing twice, but a new blockhash produces a new signature and can repeat the action. For [declared tips](/docs/swqos/tips#what-is-billed), increasing the tip on a repeated signature can increase the charge.
