A simple bitcoin JSON RPC proxy.
What is This?
This project is a node.js based bitcoin JSON RPC proxy, used by this frontend Blockchain explorer.
Note that this proxy needs to communicate with a Bitcoin Core full node (bitcoind / bitcoin-qt) instance, which you should install on your machine / network.
Running the Proxy
- Clone the project
- Go into the project folder:
- Install dependencies and compile:
- Run the proxy server:
- That's it!
Configuring the Bitcoin Core Node
A bitcoin full node does not by default listen to JSON RPC requests, so we need to configure
bitcoin.conf as the following example:
server=1 disablewallet=1 rpcuser=<username-of-your-choice> rpcpassword=<password-of-your-choice> txindex=1 rpcallowip=127.0.0.1
server=1property tells the node to run the JSON RPC service and accept connection requests (by default for mainnet on port 8332)
txindex=1tells the node to maintain a transactions index. Without it, the node will not index transactions (only blocks) so we won’t be able to run RPC queries to get raw transaction details. If you forget to set this flag before running the node and then want to enable it, then you’ll first need to run the node with the -reindex command line argument to construct the transactions index.
disablewallet=1tells the node not to provide any wallet management functionality, as we’re only interested in querying the blockchain data for the sake of this exercise.
rpcallowip=127.0.0.1tells the node to accept incoming connections on the local interface. If you plan to install the proxy on a different machine than the bitcoin core node, you'll need to either set the ip address to your proxy's machine address, or add more
rpcallowipentries (you can add as many as you need), or install a local reverse proxy to tunnel requests from all interfaces to the local 127.0.0.1 interface.
Proxy REST Endpoints
- GET /api/health
- POST /api/connect
- GET /api/disconnect
- GET /api/get-block-count
- GET /api/get-blockchain-info
- GET /api/get-block/:blockhash
- GET /api/get-raw-transaction/:txid