# estimatesmartfee

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://bitcoin-mainnet.g.alchemy.com/v2/{apiKey}

Estimates the approximate fee per kilobyte required for a transaction to begin confirmation within `conf_target` blocks. Uses BIP 141 virtual transaction size.


Reference: https://www.alchemy.com/docs/chains/bitcoin/bitcoin-api-endpoints/estimatesmartfee

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| conf_target | integer | Yes | Number of blocks within which confirmation is targeted. |
| estimate_mode | enum | No | Fee estimate mode. Options are "UNSET", "ECONOMICAL", or "CONSERVATIVE".  |

## Result

**result** (object): Estimated fee rate and corresponding target blocks.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "estimatesmartfee",
  "params": [
    1,
    "UNSET"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "feerate": 0.00002465,
    "blocks": 2
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "estimatesmartfee",
  "params": [
    1,
    "UNSET"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({jsonrpc: '2.0', id: 1, method: 'estimatesmartfee', params: [1, 'UNSET']})
};

fetch('https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "estimatesmartfee",
    "params": [1, "UNSET"]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"estimatesmartfee\",\n  \"params\": [\n    1,\n    \"UNSET\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"estimatesmartfee\",\n  \"params\": [\n    1,\n    \"UNSET\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"estimatesmartfee\",\n  \"params\": [\n    1,\n    \"UNSET\"\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: estimatesmartfee
summary: Estimate smart fee for confirmation within target blocks
description: |
  Estimates the approximate fee per kilobyte required for a transaction to begin confirmation within `conf_target` blocks. Uses BIP 141 virtual transaction size.
params:
  - name: conf_target
    required: true
    description: Number of blocks within which confirmation is targeted.
    schema:
      type: integer
      minimum: 1
      maximum: 1008
  - name: estimate_mode
    required: false
    description: |
      Fee estimate mode. Options are "UNSET", "ECONOMICAL", or "CONSERVATIVE".
    schema:
      type: string
      enum:
        - UNSET
        - ECONOMICAL
        - CONSERVATIVE
result:
  name: result
  description: Estimated fee rate and corresponding target blocks.
  schema:
    type: object
    properties:
      feerate:
        type: number
        format: double
        description: Estimated fee rate in BTC per KB.
      blocks:
        type: integer
        description: The actual confirmation target (may differ if estimate unavailable).
examples:
  - name: estimatesmartfee example
    params:
      - name: conf_target
        value: 1
      - name: estimate_mode
        value: UNSET
    result:
      name: result
      value:
        feerate: 0.00002465
        blocks: 2
```
