Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Transaction Parameters

Icon LinkTransaction 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 Icon Link 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.
Icon InfoCircle

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:

// #import { TxParams, bn };
 
const txParams: TxParams = {
  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
};

Icon LinkSetting Transaction Parameters

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

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

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

const { transactionResult } = await contract.functions
  .increment_count(15)
  .txParams({
    variableOutputs: 1,
  })
  .call();
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.