Once a transaction has been submitted, you may want to extract information regarding the result of the transaction. The SDK offers a TransactionResponse
class with helper methods to expose the following information:
Firstly, we can extract this information from the result of a submitted transaction:
// Call a contract function
const call = await contract.functions.increment_counter(15).call();
// Wait for the result
const { transactionResponse } = await call.waitForResult();
// Retrieve the full transaction summary
const transactionSummary = await transactionResponse.getTransactionSummary();
We can also use the result of a transaction request to extract a transaction summary:
// #import { ScriptTransactionRequest, TransactionResponse };
// Instantiate the transaction request using a ScriptTransactionRequest and set
// the script main function arguments
const transactionRequest = new ScriptTransactionRequest({
script: SumScript.bytecode,
});
transactionRequest.setData(SumScript.abi, scriptMainFunctionArguments);
// Fund the transaction
const txCost = await wallet.getTransactionCost(transactionRequest);
transactionRequest.maxFee = txCost.maxFee;
transactionRequest.gasLimit = txCost.gasUsed;
await wallet.fund(transactionRequest, txCost);
// Submit the transaction
const response: TransactionResponse = await wallet.sendTransaction(transactionRequest);
// Generate the transaction summary
const transactionSummary = await response.getTransactionSummary();
Or we can build a transaction summary from a stored transaction ID:
// Take a transaction ID from a previous transaction
const transactionId = previouslySubmittedTransactionId;
// 0x...
// Retrieve the transaction response from the transaction ID
const transactionResponse = await TransactionResponse.create(transactionId, provider);
// Generate the transaction summary
const transactionSummary = await transactionResponse.getTransactionSummary();