Skip to content

calculateTransactionsCost

calculateTransactionsCost(totalGas, options): bigint

Calculates the cost of a batch of transactions in satoshis, considering gas usage, fee rate, and transaction types.

The function uses internal constants and a script size map to determine the cost based on the transaction types. The formula includes gas price, script size, and asset-specific values, all converted to satoshis.

Usage

ts
import { calculateTransactionsCost } from '@midl/executor';

const cost = calculateTransactionsCost(1000000n, {
  feeRate: 2, // fee rate in satoshis per byte
  hasRunesDeposit: true,
  hasWithdraw: false,
  hasRunesWithdraw: false,
  assetsToWithdrawSize: 0,
});

Parameters

NameTypeDescription
totalGasbigintThe total gas used by the transactions.
options.feeRatenumberFee rate in satoshis per byte.
options.hasRunesDepositbooleanWhether the batch includes a runes deposit.
options.hasWithdrawbooleanWhether the batch includes a Bitcoin withdrawal.
options.hasRunesWithdrawbooleanWhether the batch includes a runes withdrawal.
options.assetsToWithdrawSizenumberThe number of assets to withdraw (default is 0).

Returns

bigint — The calculated cost of the transactions in satoshis.