Bitcoin: REST API Documentation
Introduction
------------
The Bitcoin Core (BTC) project provides a RESTful API for interacting with its blockchain. This article provides a detailed overview of the REST API, including how to use it and some examples of its functionality.
Getting Started
----------------
To begin using the BTC REST API, you will need to obtain an API key from the official Bitcoin Core website. You can do this by registering on the [official website](
Once you have obtained your API key, you can use it to create a client library in your preferred programming language (e.g. Python, JavaScript, Ruby). The client library will provide an interface to access the BTC REST API.
REST API Endpoints
-----------------
The BTC REST API provides several endpoints for interacting with the blockchain:
Blocks: Get the latest block by ID or get all blocks.
Transactions: Get a transaction's details by ID or get all transactions.
Wallets
: Get wallet information, including balance and address.
Nodes: Gets node information, including network status and nodes available.
Getting the Latest Block
To get the latest block, you can use the following endpoint:
GET /blockchain/v1/block/last_block
Replace /blockchain/v1
with your desired version (e.g. v1
for Bitcoin Core 0.7.x).
Transaction Details
To get a transaction's details by ID or get all transactions, you can use the following endpoints:
GET /transaction/v1/transaction/{txid}
Replace {txid}
with the desired transaction ID.
For example, to get a transaction's details by ID:
GET /transaction/v1/transaction/1234567890abcdef
Wallet Information
To get wallet information, including balance and address, you can use the following endpoint:
GET /wallets/v1/wallet/{walletid}
Replace {walletyid}
with the desired wallet ID.
For example, to get a wallet's details by ID:
GET /wallets/v1/wallet/1234567890abcdef
Node Information
To get node information, including network status and nodes available, you can use the following endpoint:
GET /nodes/v1/nodes
This endpoint returns a list of all available nodes in your local network.
Example Client Code (Python)
-----------------------------
Here is an example client code for using the BTC REST API with Python:
import requests

Set up API key and version
api_key = "YOUR_API_KEY_HERE"
version = "0.7.x"
Set up endpoint URL
endpoint_url = f"
Create a client library object
client = requests.Customer()
try:
Get the latest block
response = client.get(endpoint_url)
Check if the response was successful
if response.status_code == 200:
Parse the JSON response
block_data = response.json()
print("Latest Block:", block_data)
else:
print(f"Error: {response.status_code}")
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
Conclusion
----------
The Bitcoin Core REST API provides a powerful tool for interacting with the blockchain. By understanding how to use this API, you can perform a wide range of tasks, from retrieving block information to managing wallet balances. This article has provided a detailed overview of the REST API and examples of its usage in Python.