İşlem gönderme, simüle etme ve yönetmeye yönelik metodlar.
sendTransaction
sendTransaction(tx: Transaction): TransactionMetadata | FailedTransactionMetadata
Bir işlemi yürütür. Başarı durumunda meta veri, hata durumunda hata ayrıntıları döndürür.
const result = client.svm.sendTransaction(signedTx);// Check for errorsif ("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());
err(), computeUnitsConsumed(),
logs() ve signature() gibi işlem sonucu özellikleri getter fonksiyonlarıdır, özellik değildir. Her zaman
parantezle çağırın.
TransactionMetadata Metodları
| Metod | Döndürür | Açıklama |
|---|---|---|
signature() | Uint8Array | İşlem imza baytları |
computeUnitsConsumed() | bigint | Kullanılan hesaplama birimleri |
logs() | string[] | Program günlükleri |
innerInstructions() | InnerInstruction[] | İç (CPI) talimatları |
returnData() | TransactionReturnData | Programlardan dönen veriler |
prettyLogs() | string | Renkli biçimlendirilmiş günlükler |
simulateTransaction
simulateTransaction(tx: Transaction): SimulatedTransactionInfo | FailedTransactionMetadata
Durumu değiştirmeden bir işlemi simüle eder.
const simResult = client.svm.simulateTransaction(signedTx);if ("err" in simResult && simResult.err()) {console.error("Simulation failed:", simResult.err());return;}// Use .meta() to get TransactionMetadataconst meta = simResult.meta();console.log("Would use", meta.computeUnitsConsumed(), "compute units");console.log("Logs:", meta.logs());// Get post-execution account statesconst postAccounts = simResult.postAccounts();console.log("Post-state accounts:", postAccounts);
Simülasyon durumu değiştirmez. Göndermeden önce işlemleri kontrol etmek için kullanın.
Blockhash Yönetimi
latestBlockhash
latestBlockhash(): Blockhash
Geçerli blockhash değerini alır.
const blockhash = client.svm.latestBlockhash();console.log("Blockhash:", blockhash);
getLatestBlockhash (client.rpc üzerinden)
İşlemleri manuel olarak oluşturmak için yaşam süresi bilgisiyle birlikte blockhash değerini alır.
Hem blockhash hem de lastValidBlockHeight döndürdüğünden RPC yardımcısını kullanın.
import {createTransactionMessage,setTransactionMessageLifetimeUsingBlockhash} from "@solana/kit";const { value: blockhashLifetime } = await client.rpc.getLatestBlockhash().send();const tx = setTransactionMessageLifetimeUsingBlockhash(blockhashLifetime,createTransactionMessage({ version: 0 }));
systemProgram() veya tokenProgram() gibi program eklentileri kullanırken
blockhash değerini kendiniz almanız gerekmez — client.sendTransaction() (ve
talimat zincirlerindeki .sendTransaction() yardımcısı) bunu sizin için halleder.
expireBlockhash
expireBlockhash(): LiteSVM
Yeni bir blockhash değerine geçer. Blockhash sona erme senaryolarını test etmek için kullanışlıdır.
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
İşlem Geçmişi
İşlem gönderdikten sonra işlemleri alabilmek için işlem geçmişini etkinleştirin:
// Enable history storage (stores last N transactions)client.svm.withTransactionHistory(100n);// Send a transactionconst result = client.svm.sendTransaction(signedTx);// Later, retrieve it by signature (base58 string)// Note: getTransaction expects a base58-encoded signature string
Is this page helpful?