Signing & Sending
Sign transaction messages and confirm landing on Agave 4.1.1.
Recipe
Quick-reference recipe card - copy-paste ready.
import {
signTransactionMessageWithSigners,
getSignatureFromTransaction,
sendAndConfirmTransactionFactory,
createSolanaRpc,
createSolanaRpcSubscriptions,
} from "@solana/kit";
const signed = await signTransactionMessageWithSigners(message);
const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
await sendAndConfirm(signed, { commitment: "confirmed" });When to reach for this:
- Submitting transfers and program instructions from TypeScript.
- Wallet-approved sends after message build.
- Scripts that need confirmation before proceeding.
Working Example
import {
createSolanaRpc,
createSolanaRpcSubscriptions,
signTransactionMessageWithSigners,
getSignatureFromTransaction,
sendAndConfirmTransactionFactory,
getBase64EncodedWireTransaction,
} from "@solana/kit";
const rpc = createSolanaRpc(process.env.RPC_URL!);
const rpcSubscriptions = createSolanaRpcSubscriptions(process.env.RPC_WSS_URL!);
const signed = await signTransactionMessageWithSigners(message);
const signature = getSignatureFromTransaction(signed);
const simulation = await rpc
.simulateTransaction(getBase64EncodedWireTransaction(signed), { sigVerify: true })
.send();
if (simulation.value.err) throw new Error(JSON.stringify(simulation.value.err));
const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
await sendAndConfirm(signed, { commitment: "confirmed" });
console.log("https://explorer.solana.com/tx/" + signature + "?cluster=devnet");What this demonstrates:
- Simulate before send to surface program errors early.
sendAndConfirmTransactionFactorypairs HTTP send with signature subscription.- Explorer links aid support and QA.
Deep Dive
How It Works
- Signing produces a wire transaction with valid Ed25519 signatures.
- RPC
sendTransactionbroadcasts to the cluster. - Confirmation waits until chosen commitment is reached.
- Errors return program logs in simulation and transaction meta.
Confirmation Options
| Strategy | Trade-off |
|---|---|
sendAndConfirm | Simple; needs WSS |
Poll getSignatureStatuses | Works HTTP-only |
signatureNotifications | Fine-grained UI state |
Gotchas
- Skipping simulation - users pay fees for predictable failures. Fix: simulate in dev and staging.
- No WSS for confirm factory - hangs or falls back. Fix: provide
rpcSubscriptions. - processed treated as final - UI rollback possible. Fix: confirm at
confirmed+. - Double submit on retry - duplicate txs if blockhash still valid. Fix: idempotency keys or new blockhash.
- Wallet partial sign - missing signer error on send. Fix: ensure all signers invoked.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
| Jito bundles | Landing priority | Devnet smoke tests |
sendTransaction only | Fire-and-forget analytics | User-facing transfers |
| Server-sponsored send | Gasless UX | Trustless self-custody only |
FAQs
Does this work on devnet?
Yes - point RPC and wallet at the same cluster.
Can I mix kit and web3.js?
Avoid in one module - migrate wholesale per route.
What about wallet adapters?
Wallets provide signers; kit builds messages.
How do I pin @solana/kit?
Lock 7.0.0 in package.json and CI.
Where are priority fees?
Compute budget instructions before send.
How to test?
Surfpool 0.12.0 or local validator with devnet clones.
Lamports or SOL?
Always bigint lamports in kit code.
Which commitment?
confirmed for UI; finalized for treasury.
Next.js server components?
Reads on server; signing in client components.
Debug failed txs?
Simulate, read logs, verify account owners.
Related
- Building Transaction Messages - compose first
- RPC & Subscriptions - WSS confirm
- Transaction UX - UI patterns
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.