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:

Gas Limit

The maximum amount of gas you're willing to allow the transaction to consume. If the transaction requires more gas than this limit, it will fail.

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

const gasLimit: BN = bn(1000);
See code in context

Max Fee

The maximum amount you're willing to pay for the transaction using the base asset. This allows users to set an upper limit on the transaction fee they are willing to pay, preventing unexpected high costs due to sudden network congestion or fee spikes.

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

const maxFee: BN = bn(10_000);
See code in context

Tip

An optional amount of the base asset to incentivise the block producer to include the transaction, ensuring faster processing for those willing to pay more. The value set here will be added to the transaction maxFee.

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

const tip: BN = bn(100);
See code in context

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.

For example, if the chain produces a new block every second, setting Maturity to 10 means the transaction will be processed after approximately 10 seconds.

ts
const maturity = 10;
See code in context

Witness Limit

The maximum byte length allowed for the transaction witnesses array. For instance, imagine a transaction that will deploy a contract. The contract bytecode will be one of the entries in the transaction witnesses. If you set this limit to 5000 and the contract bytecode length is 6000, the transaction will be rejected because the witnesses bytes length exceeds the maximum value set.

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

const witnessLimit: BN = bn(5000);
See code in context

Variable Outputs

The number of variable outputs that should be added to the transaction request. You can read more about it on this guide

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 = {
  gasLimit: bn(1), // BigNumberish or undefined
  maxFee: bn(1), // BigNumberish or undefined
  maturity: 1, // number or undefined
  tip: 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: SumScript.bytecode,
  gasLimit: 100,
});
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 { waitForResult } = await contract.functions
  .increment_counter(15)
  .txParams({
    variableOutputs: 1,
  })
  .call();

const { transactionResult } = await waitForResult();
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.