Skip to content

Transaction Policies

Transaction policies are rules that can govern how a transaction is processed, introduced by the transaction parameters that you pass to a transaction request. The available policies are as follows:

  1. Gas Price - Maximum gas price for transaction.
  2. Witness Limit - The maximum amount of witness data allowed for the transaction.
  3. Maturity - Block until which the transaction cannot be included.
  4. Max Fee - The maximum fee payable by this transaction.

Setting Transaction Policies

The below snippet will show which transaction parameters set which policy:

ts
import { ScriptTransactionRequest } from 'fuels';

const transactionRequest = new ScriptTransactionRequest({
  gasPrice: bn(1), // Sets the gas price policy
  witnessLimit: bn(1), // Sets the witness limit policy
  maturity: 1, // Sets the maturity policy
  maxFee: bn(1), // Sets the max fee policy
});
See code in context

Retrieving Transaction Policies from a Transaction

Policies used for a transaction can be retrieved from a transaction using a TransactionResponse. The below snippet will show how to retrieve the policies from a transaction:

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

// Instantiate the transaction request with transaction parameters that would
// set the respective policies.
const transactionRequest = new ScriptTransactionRequest({
  script: scriptBytecode,
  gasLimit: bn(1_000),
  maturity: 2,
  gasPrice: bn(3),
  witnessLimit: 900,
  maxFee: bn(10_000),
});

// Set the script main function arguments
transactionRequest.setData(scriptAbi, scriptMainFunctionArguments);

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

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

// Retrieve the policies from the transaction response. The policies property
// is undefined if the transaction had no policies applied.
const policies: Policy[] | undefined = response.transaction.policies;
See code in context