# Fees

Endpoints for fee estimation.

## Get approximate fees for the given transaction

> Get an estimated fee for the 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\
> &#x20; the TransactionPayload for the transaction.\
> \* \`estimated\_len\` is an optional argument that provides the\
> &#x20; endpoint with an estimation of the final length (in bytes)\
> &#x20; of the transaction, including any post-conditions and\
> &#x20; 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\
> &#x20; database error while trying to estimate the costs of the\
> &#x20; supplied transaction.\
> \* \`NoEstimateAvailable\` - this Stacks node has not seen this\
> &#x20; kind of contract-call before, and it cannot provide an\
> &#x20; estimate yet.\
> \* \`CostEstimationDisabled\` - this Stacks node does not perform\
> &#x20; fee or cost estimation, and it cannot respond on this\
> &#x20; endpoint.\
> \
> The 200 response contains the following data:\
> \
> \* \`estimated\_cost\` - the estimated multi-dimensional cost of\
> &#x20; executing the Clarity VM on the provided transaction.\
> \* \`estimated\_cost\_scalar\` - a unitless integer that the Stacks\
> &#x20; node uses to compare how much of the block limit is consumed\
> &#x20; by different transactions. This value incorporates the\
> &#x20; estimated length of the transaction and the estimated\
> &#x20; execution cost of the transaction. The range of this integer\
> &#x20; may vary between different Stacks nodes. In order to compute\
> &#x20; an estimate of total fee amount for the transaction, this\
> &#x20; value is multiplied by the same Stacks node"s estimated fee\
> &#x20; rate.\
> \* \`cost\_scalar\_change\_by\_byte\` - a float value that indicates how\
> &#x20; much the \`estimated\_cost\_scalar\` value would increase for every\
> &#x20; additional byte in the final transaction.\
> \* \`estimations\` - an array of estimated fee rates and total fees to\
> &#x20; pay in microSTX for the transaction. This array provides a range of\
> &#x20; estimates (default: 3) that may be used. Each element of the array\
> &#x20; contains the following fields:\
> &#x20;   \* \`fee\_rate\` - the estimated value for the current fee\
> &#x20;     rates in the network\
> &#x20;   \* \`fee\` - the estimated value for the total fee in\
> &#x20;     microSTX that the given transaction should pay. These\
> &#x20;     values are the result of computing:\
> &#x20;     \`fee\_rate\` x \`estimated\_cost\_scalar\`.\
> &#x20;     If the estimated fees are less than the minimum relay\
> &#x20;     fee \`(1 ustx x estimated\_len)\`, then that minimum relay\
> &#x20;     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:\
> \
> &#x20; \`fee\_rate\` x \`cost\_scalar\_change\_by\_byte\` x (\`final\_size\` - \`estimated\_size\`)<br>

```json
{"openapi":"3.1.0","info":{"title":"Stacks 3.0+ RPC API","version":"1.0.0"},"tags":[{"name":"Fees","description":"Endpoints for fee estimation."}],"servers":[{"url":"http://localhost:20443","description":"Local Stacks Node"},{"url":"https://api.mainnet.hiro.so","description":"Stacks Mainnet API"},{"url":"https://api.testnet.hiro.so","description":"Stacks Testnet API"}],"security":[],"paths":{"/v2/fees/transaction":{"post":{"summary":"Get approximate fees for the given transaction","tags":["Fees"],"description":"Get an estimated fee for the supplied transaction.  This\nestimates the execution cost of the transaction, the current\nfee rate of the network, and returns estimates for fee\namounts.\n\n* `transaction_payload` is a hex-encoded serialization of\n  the TransactionPayload for the transaction.\n* `estimated_len` is an optional argument that provides the\n  endpoint with an estimation of the final length (in bytes)\n  of the transaction, including any post-conditions and\n  signatures\n\nIf the node cannot provide an estimate for the transaction\n(e.g., if the node has never seen a contract-call for the\ngiven contract and function) or if estimation is not\nconfigured on this node, a 400 response is returned.\nThe 400 response will be a JSON error containing a `reason`\nfield which can be one of the following:\n\n* `DatabaseError` - this Stacks node has had an internal\n  database error while trying to estimate the costs of the\n  supplied transaction.\n* `NoEstimateAvailable` - this Stacks node has not seen this\n  kind of contract-call before, and it cannot provide an\n  estimate yet.\n* `CostEstimationDisabled` - this Stacks node does not perform\n  fee or cost estimation, and it cannot respond on this\n  endpoint.\n\nThe 200 response contains the following data:\n\n* `estimated_cost` - the estimated multi-dimensional cost of\n  executing the Clarity VM on the provided transaction.\n* `estimated_cost_scalar` - a unitless integer that the Stacks\n  node uses to compare how much of the block limit is consumed\n  by different transactions. This value incorporates the\n  estimated length of the transaction and the estimated\n  execution cost of the transaction. The range of this integer\n  may vary between different Stacks nodes. In order to compute\n  an estimate of total fee amount for the transaction, this\n  value is multiplied by the same Stacks node\"s estimated fee\n  rate.\n* `cost_scalar_change_by_byte` - a float value that indicates how\n  much the `estimated_cost_scalar` value would increase for every\n  additional byte in the final transaction.\n* `estimations` - an array of estimated fee rates and total fees to\n  pay in microSTX for the transaction. This array provides a range of\n  estimates (default: 3) that may be used. Each element of the array\n  contains the following fields:\n    * `fee_rate` - the estimated value for the current fee\n      rates in the network\n    * `fee` - the estimated value for the total fee in\n      microSTX that the given transaction should pay. These\n      values are the result of computing:\n      `fee_rate` x `estimated_cost_scalar`.\n      If the estimated fees are less than the minimum relay\n      fee `(1 ustx x estimated_len)`, then that minimum relay\n      fee will be returned here instead.\n\n\nNote: If the final transaction\"s byte size is larger than\nsupplied to `estimated_len`, then applications should increase\nthis fee amount by:\n\n  `fee_rate` x `cost_scalar_change_by_byte` x (`final_size` - `estimated_size`)\n","operationId":"getFeeTransaction","requestBody":{"content":{"application/json":{"schema":{"description":"POST request for estimated fee","type":"object","additionalProperties":false,"required":["transaction_payload"],"properties":{"transaction_payload":{"type":"string"},"estimated_len":{"type":"integer"}}}}}},"responses":{"200":{"description":"Estimated fees for the transaction","content":{"application/json":{"schema":{"description":"POST response for estimated fee","type":"object","additionalProperties":false,"required":["estimated_cost","estimated_cost_scalar","cost_scalar_change_by_byte","estimations"],"properties":{"estimated_cost":{"type":"object","additionalProperties":false,"required":["read_count","write_count","read_length","write_length","runtime"],"properties":{"read_count":{"type":"integer","minimum":0},"read_length":{"type":"integer","minimum":0},"runtime":{"type":"integer","minimum":0},"write_count":{"type":"integer","minimum":0},"write_length":{"type":"integer","minimum":0}}},"estimated_cost_scalar":{"type":"integer","minimum":0},"cost_scalar_change_by_byte":{"type":"number","minimum":0},"estimations":{"type":"array","items":{"type":"object","properties":{"fee_rate":{"type":"number","minimum":0},"fee":{"type":"integer","minimum":0}}}}}}}}},"400":{"description":"Fee estimation error","content":{"application/json":{"schema":{"type":"object","description":"Returned when the node cannot calculate a fee estimate.\n","required":["error","reason"],"properties":{"error":{"type":"string","description":"Human-readable summary of the failure."},"reason":{"type":"string","description":"Machine-readable error code.","enum":["DatabaseError","NoEstimateAvailable"]},"reason_data":{"type":["object","null"],"description":"Optional structured details specific to `reason`.\nFor the current implementation it contains a `message` field,\nbut additional fields may be added in future.\n","properties":{"message":{"type":"string"}},"additionalProperties":true}}}},"text/plain":{"schema":{"type":"string"}}}},"500":{"description":"Internal Server Error","content":{"text/plain":{"schema":{"type":"string"}}}}}}}}}
```

## Get estimated fee

> Get an estimated fee rate for STX transfer transactions. This is a fee\
> rate per byte, returned as a JSON integer (microSTX per byte).<br>

```json
{"openapi":"3.1.0","info":{"title":"Stacks 3.0+ RPC API","version":"1.0.0"},"tags":[{"name":"Fees","description":"Endpoints for fee estimation."}],"servers":[{"url":"http://localhost:20443","description":"Local Stacks Node"},{"url":"https://api.mainnet.hiro.so","description":"Stacks Mainnet API"},{"url":"https://api.testnet.hiro.so","description":"Stacks Testnet API"}],"security":[],"paths":{"/v2/fees/transfer":{"get":{"summary":"Get estimated fee","tags":["Fees"],"operationId":"getFeeTransfer","description":"Get an estimated fee rate for STX transfer transactions. This is a fee\nrate per byte, returned as a JSON integer (microSTX per byte).\n","responses":{"200":{"description":"Fee rate in microSTX per byte","content":{"application/json":{"schema":{"type":"integer","minimum":1,"description":"Fee rate in microSTX per byte"}}}},"500":{"description":"Internal Server Error","content":{"text/plain":{"schema":{"type":"string"}}}}}}}}}
```
