Skip to content

useEstimateBTCTransaction

Estimates the cost and gas requirements for a Bitcoin transaction with the provided intentions. Calculates gas limits for EVM transactions and total fees without executing the transaction.

Import

ts
import { useEstimateBTCTransaction } from "@midl/executor-react";

Example

ts
const { data: estimation, isLoading, error } = useEstimateBTCTransaction(intentions, {
  feeRate: 10,
  gasMultiplier: 1.5
});

console.log(`Estimated fee: ${estimation?.fee} satoshis`);
console.log(`Updated intentions:`, estimation?.intentions);

Parameters

NameTypeDescription
intentionsTransactionIntention[]Array of transaction intentions to estimate.
optionsUseEstimateBTCTransactionParams (optional)Optional configuration and query options.

UseEstimateBTCTransactionParams

Extends EstimateBTCTransactionOptions with additional query options:

NameTypeDescription
stateOverrideStateOverride (optional)State override for EVM transactions.
fromstring (optional)BTC address of the account to use for signing.
feeRatenumber (optional)Custom fee rate (sats/vB).
multisigAddressstring (optional)Multisig address to use for the transaction.
gasMultipliernumber (optional)Multiplier to apply to estimated gas (default: 1.2). Used to avoid gas fluctuations.
queryUseQueryOptions (optional)Query options for React Query.
configConfig (optional)Custom configuration to override the default.

Returns

Returns a React Query result object with the following properties:

NameTypeDescription
dataEstimateBTCTransactionResponse | undefinedThe estimation response containing fee and updated intentions.
isLoadingbooleanWhether the query is currently loading.
isErrorbooleanWhether the query has an error.
errorError | nullThe error object if the query failed.
isSuccessbooleanWhether the query completed successfully.
refetch() => voidFunction to manually refetch the estimation.
...restobjectAdditional query state from React Query.

EstimateBTCTransactionResponse

NameTypeDescription
feebigintThe estimated total cost in satoshis.
intentionsTransactionIntention[]The cloned intentions with updated gas limits for EVM transactions.

Query Behavior

  • The query is enabled by default when:
    • A network is set in the configuration
    • The intentions array is not empty
  • The query is disabled when:
    • No network is configured
    • The intentions array is empty
    • Explicitly disabled via query.enabled: false
  • The query will automatically refetch when the intentions parameter changes

Released under the MIT License.