Skip to content

Transaction Response

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:

  • The transaction ID
  • The status (submitted, success, squeezed out, or failure)
  • Receipts (return data, logs, mints/burns, transfers and panic/reverts)
  • Gas fees and usages
  • The raw payload of the transaction including inputs and outputs
  • Date and time of the transaction
  • The block the transaction was included in

Firstly, we can extract this information from the result of a submitted transaction:

ts
import { TransactionResponse } from 'fuels';

// Call a contract function
const call = await contract.functions.increment_count(15).call();

// Pick off the transaction response
const transactionResponse: TransactionResponse = call.transactionResponse;

// Retrieve the full transaction summary
const transactionSummary = await transactionResponse.getTransactionSummary();
See code in context

We can also use the result of a transaction request to extract a transaction summary:

ts
import { ScriptTransactionRequest, TransactionResponse } from 'fuels';

// Instantiate the transaction request using a ScriptTransactionRequest and set
// the script main function arguments
const transactionRequest = new ScriptTransactionRequest({
  script: scriptBytecode,
  gasPrice,
});
transactionRequest.setData(scriptAbi, scriptMainFunctionArguments);

// Fund the transaction
transactionRequest.addResources(resources);

// Submit the transaction
const response: TransactionResponse = await wallet.sendTransaction(transactionRequest);

// Generate the transaction summary
const transactionSummary = await response.getTransactionSummary();
See code in context

Or we can build a transaction summary from a stored transaction ID:

ts
import { TransactionResponse } from 'fuels';

// 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();
See code in context