BTC - Fee Estimate

Modified on Mon, 23 Oct 2023 at 03:59 PM

TABLE OF CONTENTS


Bitcoin (BTC) is a UTXO-based chain, where the Fee estimate for a transaction fee comes from two main parameters:

  • Approximate fee per kilobyte
  • Transaction size

The Formula

Estimated Fee == "approximate fee per kilobyte" * "transaction size"


Calculating the approximate fee per kilobyte

To estimate the fee for a BTC transaction, you can use the Tatum endpoint for BTC "fee estimate"

curl --location 'https://api.tatum.io/v3/blockchain/fee/BTC' \
--header 'x-api-key: {your_api_key}' \
--data ''
//response:
{
    "fast": 13.5, // Satoshis per byte == 0.0135 satoshis per kilobyte.
    "medium": 5,
    "slow": 4,
    "block": 813488, //last used to calculate fee from
    "time": "2023-10-23T12:14:42.817Z" // last time when calculation was executed
}
More information at the following link.


There's also the option to make a cURL RPC node request:

curl --location 'https://api.tatum.io/v3/blockchain/node/BTC/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {your_api_key}' \
--data '{
    "jsonrpc":"1.0",
    "id":"curltext",
    "method":"estimatesmartfee",
    "params":[2] // specifies the target confirmation time in blocks.
//response:
{
    "result": {
        "feerate": 0.00001, // Satoshis per Kilobyte
        "blocks": 2
    },
    "error": null,
    "id": "curltext"
}

Calculating the transaction size

Transaction Size (in bytes) = (Number of Inputs * 148) + (Number of Outputs * 34) + 10

  • Number of Inputs: The number of transaction inputs (unspent transaction outputs or UTXOs) that your transaction is spending.
  • Number of Outputs: The number of transaction outputs, including the recipient's address and any change addresses.
  • 10 bytes: A fixed overhead for the transaction header.


Let's break it down:

  • Number of Inputs * 148 bytes: Each input typically takes 148 bytes. This includes the previous transaction's reference (36 bytes) plus a scriptSig (typically 110 bytes) for unlocking the UTXO and some additional bytes for metadata.
  • Number of Outputs * 34 bytes: Each output typically takes 34 bytes. This includes 8 bytes for the amount in satoshis, 1 byte for the OP_RETURN code (if used), and 25 bytes for the recipient's public key or address.


Example of a BTC transaction with 2 inputs and 2 outputs:

  • Number of Inputs = 2
  • Number of Outputs = 2


Using the formula:

  • Transaction Size (in bytes) = (2 * 148) + (2 * 34) + 10
  • Transaction Size (in bytes) = 296 + 68 + 10
  • Transaction Size (in bytes) = 374 bytes


So, the transaction size in this example is 374 bytes.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article