Get fee estimate

Retrieves an estimated fee rate for transactions.

POST

/v2/fees/transaction

Get an estimated fee for a supplied transaction. This estimates the execution cost of the transaction, the current fee rate of the network, and returns estimates for fee amounts.

  • transaction_payload is a hex-encoded serialization of the TransactionPayload for the transaction.
  • estimated_len is an optional argument that provides the endpoint with an estimation of the final length (in bytes) of the transaction, including any post-conditions and signatures.

If the node cannot provide an estimate for the transaction (e.g., if the node has never seen a contract-call for the given contract and function) or if estimation is not configured on this node, a 400 response is returned.

The 400 response will be a JSON error containing a reason field which can be one of the following:

  • DatabaseError: This Stacks node has had an internal database error while trying to estimate the costs of the supplied transaction.
  • NoEstimateAvailable: This Stacks node has not seen this kind of contract-call before, and it cannot provide an estimate yet.
  • CostEstimationDisabled: This Stacks node does not perform fee or cost estimation, and it cannot respond on this endpoint.

The 200 response contains the following data:

  • estimated_cost: The estimated multi-dimensional cost of executing the Clarity VM on the provided transaction.
  • estimated_cost_scalar: A unitless integer that the Stacks node uses to compare how much of the block limit is consumed by different transactions. This value incorporates the estimated length of the transaction and the estimated execution cost of the transaction. The range of this integer may vary between different Stacks nodes. In order to compute an estimate of total fee amount for the transaction, this value is multiplied by the same Stacks node's estimated fee rate.
  • cost_scalar_change_by_byte: A float value that indicates how much the estimated_cost_scalar value would increase for every additional byte in the final transaction.
  • estimations: An array of estimated fee rates and total fees to pay in microSTX for the transaction. This array provides a range of estimates (default: 3) that may be used. Each element of the array contains the following fields:
    • fee_rate: The estimated value for the current fee rates in the network
    • fee: The estimated value for the total fee in microSTX that the given transaction should pay. These values are the result of computing fee_rate x estimated_cost_scalar. If the estimated fees are less than the minimum relay fee (1 ustx x estimated_len), then that minimum relay fee will be returned here instead.

Note: If the final transaction's byte size is larger than supplied to estimated_len, then applications should increase this fee amount by: fee_rate x cost_scalar_change_by_byte x (final_size - estimated_size)

Request body (optional)

transaction_payload
Required
string

estimated_leninteger

Status codeDescription
200Estimated fees for the transaction
Terminal
curl -X POST "https://api.mainnet.hiro.so/v2/fees/transaction" \
  -d '{
  "transaction_payload": "string",
  "estimated_len": 0
}'

POST response for estimated fee

Example response
{
  "estimated_cost_scalar": 0,
  "cost_scalar_change_by_byte": 0,
  "estimated_cost": {
    "read_count": 0,
    "read_length": 0,
    "runtime": 0,
    "write_count": 0,
    "write_length": 0
  },
  "estimations": [
    {
      "fee_rate": 0,
      "fee": 0
    }
  ]
}