Solana-DokumentationLiteSVMTypeScriptAPI-Referenz

Transaktionen

Methoden zum Senden, Simulieren und Verwalten von Transaktionen.

sendTransaction

sendTransaction(tx: Transaction): TransactionMetadata | FailedTransactionMetadata

Eine Transaktion ausführen. Gibt bei Erfolg Metadaten oder bei einem Fehler Details zum Fehlschlag zurück.

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());

Ergebniseigenschaften einer Transaktion wie err(), computeUnitsConsumed(), logs() und signature() sind Getter-Funktionen, keine Eigenschaften. Immer mit Klammern aufrufen.

TransactionMetadata-Methoden

MethodeRückgabeBeschreibung
signature()Uint8ArrayTransaktionssignatur-Bytes
computeUnitsConsumed()bigintVerbrauchte Compute-Units
logs()string[]Programm-Logs
innerInstructions()InnerInstruction[]Interne (CPI) Anweisungen
returnData()TransactionReturnDataRückgabedaten von Programmen
prettyLogs()stringFormatierte Logs mit Farben

simulateTransaction

simulateTransaction(tx: Transaction): SimulatedTransactionInfo | FailedTransactionMetadata

Eine Transaktion simulieren, ohne den Zustand zu ändern.

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);

Die Simulation ändert den Zustand nicht. Verwende sie, um Transaktionen vor dem Senden zu prüfen.

Blockhash-Verwaltung

latestBlockhash

latestBlockhash(): Blockhash

Den aktuellen Blockhash abrufen.

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

getLatestBlockhash (über client.rpc)

Den Blockhash mit Lebensdauerinformationen zum manuellen Erstellen von Transaktionen abrufen. Verwende den RPC-Helfer, da er sowohl blockhash als auch lastValidBlockHeight zurückgibt.

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

Bei der Verwendung von Programm-Plugins wie systemProgram() oder tokenProgram() musst du den Blockhash nie selbst abrufen — client.sendTransaction() (und der .sendTransaction()-Helfer bei Anweisungsketten) erledigt das für dich.

expireBlockhash

expireBlockhash(): LiteSVM

Zu einem neuen Blockhash wechseln. Nützlich zum Testen von Blockhash-Ablaufszenarien.

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

Transaktionsverlauf

Den Transaktionsverlauf aktivieren, um Transaktionen nach dem Senden abzurufen:

// 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?

Inhaltsverzeichnis

Seite bearbeiten
© 2026 Solana Foundation. Alle Rechte vorbehalten.