Transactions

Transactions

Methods for sending, simulating, and managing transactions.

sendTransaction

sendTransaction(tx: Transaction): TransactionMetadata | FailedTransactionMetadata

Execute a transaction. Returns metadata on success or failure details on error.

const result = client.svm.sendTransaction(signedTx);
// Check for errors
if ("err" in result && result.err()) {
console.error("Transaction failed:", result.err());
return;
}
// Access result properties (note: these are getter functions)
console.log("Signature:", result.signature());
console.log("Compute units:", result.computeUnitsConsumed());
console.log("Logs:", result.logs());

Transaction result properties like err(), computeUnitsConsumed(), logs(), and signature() are getter functions, not properties. Always call them with parentheses.

TransactionMetadata Methods

MethodReturnsDescription
signature()Uint8ArrayTransaction signature bytes
computeUnitsConsumed()bigintCompute units used
logs()string[]Program logs
innerInstructions()InnerInstruction[]Inner (CPI) instructions
returnData()TransactionReturnDataReturn data from programs
prettyLogs()stringFormatted logs with colors

simulateTransaction

simulateTransaction(tx: Transaction): SimulatedTransactionInfo | FailedTransactionMetadata

Simulate a transaction without modifying state.

const simResult = client.svm.simulateTransaction(signedTx);
if ("err" in simResult && simResult.err()) {
console.error("Simulation failed:", simResult.err());
return;
}
// Use .meta() to get TransactionMetadata
const meta = simResult.meta();
console.log("Would use", meta.computeUnitsConsumed(), "compute units");
console.log("Logs:", meta.logs());
// Get post-execution account states
const postAccounts = simResult.postAccounts();
console.log("Post-state accounts:", postAccounts);

Simulation doesn't change state. Use it to check transactions before sending.

Blockhash Management

latestBlockhash

latestBlockhash(): Blockhash

Get the current blockhash.

const blockhash = client.svm.latestBlockhash();
console.log("Blockhash:", blockhash);

getLatestBlockhash (via client.rpc)

Get the blockhash with lifetime information for building transactions manually. Use the RPC helper since it returns both blockhash and lastValidBlockHeight.

import {
createTransactionMessage,
setTransactionMessageLifetimeUsingBlockhash
} from "@solana/kit";
const { value: blockhashLifetime } = await client.rpc
.getLatestBlockhash()
.send();
const tx = setTransactionMessageLifetimeUsingBlockhash(
blockhashLifetime,
createTransactionMessage({ version: 0 })
);

When using program plugins like systemProgram() or tokenProgram(), you never need to fetch the blockhash yourself — client.sendTransaction() (and the .sendTransaction() helper on instruction chains) handle it for you.

expireBlockhash

expireBlockhash(): LiteSVM

Advance to a new blockhash. Useful for testing blockhash expiration scenarios.

const oldBlockhash = client.svm.latestBlockhash();
client.svm.expireBlockhash();
const newBlockhash = client.svm.latestBlockhash();
console.log("Old:", oldBlockhash);
console.log("New:", newBlockhash);
// Blockhashes will be different

Transaction History

Enable transaction history to retrieve transactions after sending:

// Enable history storage (stores last N transactions)
client.svm.withTransactionHistory(100n);
// Send a transaction
const result = client.svm.sendTransaction(signedTx);
// Later, retrieve it by signature (base58 string)
// Note: getTransaction expects a base58-encoded signature string

Is this page helpful?

Índice

Editar Página
© 2026 Fundação Solana. Todos os direitos reservados.
Transactions | Solana