Skip to content

Transaction Parameters

Transaction parameters allow you to configure various aspects of your blockchain transactions. Dependent on these parameters, it may introduce a transaction policy. The parameters are:

  1. Gas Price - The price you're willing to pay for each unit of gas consumed during the transaction execution.
  2. Gas Limit - The maximum amount of gas you're willing to allow the transaction to consume. If the amount of gas a transaction will use is greater than the gas limit, the transaction will fail.
  3. Max Fee - The maximum amount you're willing to pay for the transaction using the base asset. This is the price of each unit of gas multiplied by the amount of gas used.
  4. Maturity - The number of blocks that must pass before the transaction can be included in a block. This is useful for time-sensitive transactions, such as those involving time-locked assets.
  5. Witness Limit - The maximum number of witnesses allowed in the transaction. Witnesses are used in transactions that require multiple signatures, such as those involving multi-signature wallets.
  6. Variable Outputs - The number of variable outputs allowed in the transaction. Variable outputs are used in transactions that have a dynamic number of outputs, such as those involving multiple recipients or complex contract interactions. By setting this value, you can control the number of variable outputs permitted in the transaction, which can be useful for managing transaction size and complexity.

Note: Setting transaction parameters is optional. If you don't specify them, the SDK will fetch some sensible defaults from the chain.

All available parameters are shown below:

ts
import type { TxParams } from 'fuels';
import { bn } from 'fuels';

const txParams: TxParams = {
  gasPrice: bn(1), // BigNumberish or undefined
  gasLimit: bn(1), // BigNumberish or undefined
  maturity: 1, // number or undefined
  maxFee: bn(1), // BigNumberish or undefined
  witnessLimit: bn(1), // BigNumberish or undefined
  variableOutputs: 1, // number or undefined
};
See code in context

Setting Transaction Parameters

To set the transaction parameters, you have access to the txParams method on a transaction request.

ts
import { ScriptTransactionRequest } from 'fuels';

// Instantiate the transaction request using a ScriptTransactionRequest
// We can set txParams in the request constructor
const transactionRequest = new ScriptTransactionRequest({
  script: scriptBytecode,
  gasLimit: 100,
  gasPrice,
});
See code in context

The same method is also accessible within a function invocation scope, so it can also be used when calling contract functions.

ts
const { transactionResult } = await contract.functions
  .increment_count(15)
  .txParams({
    gasLimit: 10_000,
    variableOutputs: 1,
  })
  .call();
See code in context

Note: When performing an action that results in a transaction (e.g. contract deployment, contract call with .call(), asset transfer), the SDK will automatically estimate the fee based on the gas limit and the transaction's byte size. This estimation is used when building the transaction. As a side effect, your wallet must own at least one coin of the base asset, regardless of the amount.