Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Transaction Parameters

Icon LinkTransaction Parameters

Transaction parameters allow you to configure various aspects of your blockchain transactions. The main parameters are:

  1. gasPrice: The price you're willing to pay for each unit of gas consumed during the transaction execution.

  2. gasLimit: The maximum amount of gas you're willing to allow the transaction to consume. If the transaction execution requires more gas than the specified gas limit, the transaction will fail, and any state changes made during the execution will be reverted.

  3. variableOutputs: Specifies 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.

export type TxParams = Partial<{
  gasPrice: BigNumberish;
  gasLimit: BigNumberish;
  maturity?: number;
  maxFee?: BigNumberish;
  witnessLimit?: BigNumberish;
  variableOutputs: number;
}>;
Icon InfoCircle

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

Icon LinkSetting Transaction Parameters

To set these parameters, use the optional TxParams object and pass it to the txParams chain method:

const { minGasPrice } = provider.getGasConfig();
 
const { transactionResult } = await contract.functions
  .increment_count(15)
  .txParams({
    gasLimit: 10_000,
    variableOutputs: 1,
  })
  .call();

If you don't provide TxParams, the values will default to those specified in the chainConfig provided to your Fuel node.

You can also set TxParams when deploying contracts or transferring assets by passing the object to the respective methods.

Icon InfoCircle

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.

 
await expect(
  contract.functions
    .increment_count(10)
    .txParams({
      gasLimit: 1,
    })
    .call()
).rejects.toThrowError(/Gas limit [\s\S]* is lower than the required/);