estimatesmartfee
Overview
The 'estimatesmartfee' RPC method allows you to estimate the smart fee per kilobyte required for a transaction to be processed within a certain number of blocks. It also returns the number of blocks for which the estimate is valid. Each call to this method consumes 1 API credit.
Request
- shell
- csharp
- php
- python
- javascript
- go
- ruby
- java
wget --no-check-certificate --quiet \
--method POST \
--timeout=0 \
--header 'Content-Type: application/json' \
--header 'accept: application/json' \
--header 'X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY' \
--body-data '{
"jsonrpc": "1.0",
"id": "1",
"method": "estimatesmartfee",
"params": []
}
' \
'https://bitcoin-mainnet.node.coinapi.io'
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://bitcoin-mainnet.node.coinapi.io");
request.Headers.Add("accept", "application/json");
request.Headers.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY");
var content = new StringContent("{\r\n \"jsonrpc\": \"1.0\",\r\n \"id\": \"1\",\r\n \"method\": \"estimatesmartfee\",\r\n \"params\": []\r\n}\r\n", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
<?php
$client = new Client();
$headers = [
'Content-Type' => 'application/json',
'accept' => 'application/json',
'X-CoinAPI-Key' => '73034021-THIS-IS-SAMPLE-KEY'
];
$body = '{
"jsonrpc": "1.0",
"id": "1",
"method": "estimatesmartfee",
"params": []
}';
$request = new Request('POST', 'https://bitcoin-mainnet.node.coinapi.io', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
?>
import requests
import json
url = "https://bitcoin-mainnet.node.coinapi.io"
payload = json.dumps({
"jsonrpc": "1.0",
"id": "1",
"method": "estimatesmartfee",
"params": []
})
headers = {
'Content-Type': 'application/json',
'accept': 'application/json',
'X-CoinAPI-Key': '73034021-THIS-IS-SAMPLE-KEY'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
var settings = {
"url": "https://bitcoin-mainnet.node.coinapi.io",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"accept": "application/json",
"X-CoinAPI-Key": "73034021-THIS-IS-SAMPLE-KEY"
},
"data": JSON.stringify({
"jsonrpc": "1.0",
"id": "1",
"method": "estimatesmartfee",
"params": []
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
package main
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://bitcoin-mainnet.node.coinapi.io"
method := "POST"
payload := strings.NewReader(`{`+"
"+`
"jsonrpc": "1.0",`+"
"+`
"id": "1",`+"
"+`
"method": "estimatesmartfee",`+"
"+`
"params": []`+"
"+`
}`+"
"+`
`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("accept", "application/json")
req.Header.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require "uri"
require "json"
require "net/http"
url = URI("https://bitcoin-mainnet.node.coinapi.io")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["accept"] = "application/json"
request["X-CoinAPI-Key"] = "73034021-THIS-IS-SAMPLE-KEY"
request.body = JSON.dump({
"jsonrpc": "1.0",
"id": "1",
"method": "estimatesmartfee",
"params": []
})
response = https.request(request)
puts response.read_body
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"jsonrpc\": \"1.0\",\r\n \"id\": \"1\",\r\n \"method\": \"estimatesmartfee\",\r\n \"params\": []\r\n}\r\n");
Request request = new Request.Builder()
.url("https://bitcoin-mainnet.node.coinapi.io")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("accept", "application/json")
.addHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
.build();
Response response = client.newCall(request).execute();
Request Parameters
'conf_target' (numeric) Requirement: Mandatory
- This parameter specifies the confirmation target in blocks.
'estimate_mode' (string) Default Value: CONSERVATIVE
- his parameter allows you to set the fee estimate mode. You can choose between different modes to get a more conservative or aggressive fee estimate.
Response
{
"blocks": 6,
"feerate": 0.00012345,
"errors": [],
"str": ""
}
'blocks' The block number where the estimate was found.
'feerate' The estimated fee rate, denoted in BTC/kB.
'errors' A list of errors encountered during the processing, if any.
'str' A string describing the error in detail, if any error was encountered.
Notes
- The 'conf_target' parameter is essential to get an accurate fee estimate. It represents the number of blocks within which you want the transaction to be confirmed.
- The 'estimate_mode' parameter allows you to tailor the fee estimate according to your preference. The default value is "CONSERVATIVE", which provides a more cautious fee estimate.
- The method returns detailed information about the estimated fee, including the block number where the estimate was found and the estimated fee rate in BTC/kB.
- If there are any errors during the processing, the method will return the errors in the 'errors' field and a detailed error description in the 'str' field.
Was this section helpful?