BitcoinMethods
getchaintips
The getchaintips RPC method provided by CoinAPI offers detailed insights into all recognized chaintips in the block tree. This encompasses information on the main chain as well as any orphaned bran...
getchaintips
Overview
The 'getchaintips' RPC method provided by CoinAPI offers detailed insights into all recognized chaintips in the block tree. This encompasses information on the main chain as well as any orphaned branches.
Request
shell
wget --no-check-certificate --quiet \
--method POST \
--timeout=0 \
--header 'Content-Type: application/json' \
--header 'accept: application/json' \
--header 'X-CoinAPI-Key: 4303fb63-adec-42dc-b571-74bc2f2a5167' \
--body-data '{"jsonrpc":"2.0","id":1,"method":"getchaintips","params": [ ]}' \
'https://bitcoin-mainnet.node.coinapi.io'csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://bitcoin-mainnet.node.coinapi.io");
request.Headers.Add("x-coinapi-key", "73034021-THIS-IS-SAMPLE-KEY");
request.Headers.Add("accept", "application/json");
var content = new StringContent("{\"jsonrpc\":\"2.0\",\"method\":\"getchaintips\",\"params\": [],\"id\":1}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());php
<?php
$client = new Client();
$headers = [
'x-coinapi-key' => '73034021-THIS-IS-SAMPLE-KEY',
'Content-Type' => 'application/json',
'accept' => 'application/json'
];
$body = '{
"jsonrpc": "2.0",
"method": "getchaintips",
"params": [],
"id": 1
}';
$request = new Request('POST', 'https://bitcoin-mainnet.node.coinapi.io', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
?>python
import requests
import json
url = "https://bitcoin-mainnet.node.coinapi.io"
payload = json.dumps({
"jsonrpc": "2.0",
"method": "getchaintips",
"params": [],
"id": 1
})
headers = {
'x-coinapi-key': '73034021-THIS-IS-SAMPLE-KEY',
'Content-Type': 'application/json',
'accept': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)javascript
var settings = {
"url": "https://bitcoin-mainnet.node.coinapi.io",
"method": "POST",
"timeout": 0,
"headers": {
"x-coinapi-key": "4303fb63-adec-42dc-b571-74bc2f2a5167",
"Content-Type": "application/json",
"accept": "application/json"
},
"data": JSON.stringify({
"jsonrpc": "2.0",
"method": "getchaintips",
"params": [],
"id": 1
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});go
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://bitcoin-mainnet.node.coinapi.io"
method := "POST"
payload := strings.NewReader(`{"jsonrpc":"2.0","method":"getchaintips","params": [],"id":1}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("x-coinapi-key", "73034021-THIS-IS-SAMPLE-KEY")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("accept", "application/json")
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))
}ruby
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["x-coinapi-key"] = "73034021-THIS-IS-SAMPLE-KEY"
request["Content-Type"] = "application/json"
request["accept"] = "application/json"
request.body = JSON.dump({
"jsonrpc": "2.0",
"method": "getchaintips",
"params": [],
"id": 1
})
response = https.request(request)
puts response.read_bodyjava
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\": \"getchaintips\",\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
This method does not require any parameters.
Response
{
"result": [
{
"height": 810528,
"hash": "00000000000000000004749a1d06c52c2442a7bec69ace34edb9a0d6e9102182",
"branchlen": 0,
"status": "active"
},
{
"height": 792379,
"hash": "000000000000000000032956cbfd8721abe0572d81542e75e38e6185312bee09",
"branchlen": 1,
"status": "valid-fork"
},
{
"height": 791130,
"hash": "00000000000000000000e66ee68d93839fbff6f01482562737c05d5be5db033e",
"branchlen": 1,
"status": "valid-headers"
}
],
"error": null,
"id": 1
}The method returns the following data:
- height: Represents the height of the chain tip.
- hash: Indicates the block hash of the tip.
- branchlen: This is zero for the main chain. For other branches, it indicates the length of the branch connecting the tip to the main chain.
- status: Describes the status of the chain. The "active" status is assigned to the main chain.
Other potential statuses include:
- invalid: This status is assigned when the branch contains at least one block that is invalid.
- headers-only: This status is assigned when only the headers are valid, but not all blocks for this branch are present.
- valid-headers: This status is assigned when the branch contains all blocks, but they haven't been fully validated.
- valid-fork: This status is assigned when the branch has been fully validated but is not part of the active chain.
- active: This status is assigned when the branch represents the tip of the active main chain, which is definitively valid.