This guide outlines the setup process for the Bitcoin Analytics App, a NestJS-based application that imports and analyzes Bitcoin blockchain data using a Bitcoin Core node and stores it in a MySQL database.
- Node.js (LTS version)
- NestJS CLI
- Bitcoin Core (v0.20.0 or later recommended)
- MySQL (v5.7 or later)
-
Install Node.js: Download and install the LTS version from Node.js official website.
-
Install NestJS CLI: Open your terminal and run the following command:
npm i -g @nestjs/cli
-
Project Setup: Clone the project repository and install dependencies:
git clone <your-repository-url> cd <project-directory> npm install
-
Edit Bitcoin Core Config: Locate your
bitcoin.conf
file and add the following lines to configure the RPC server, enable the transaction index, and adjust the RPC work queue. Thebitcoin.conf
file is typically found in the Bitcoin data directory.server=1 txindex=1 rpcuser=<your-rpc-username> rpcpassword=<your-rpc-password> rpcworkqueue=128
-
Restart Bitcoin Core: For the changes to take effect, restart your Bitcoin Core node.
- Increase
ulimit
: To increase the number of allowable open files for the system, which is beneficial for both Bitcoin Core and the MySQL database, you can use the following command:It's recommended to add this command to yourulimit -n 4096
.bashrc
or.bash_profile
for persistence across sessions.
- Configure
.env
File: Create a.env
file in the root of your project directory with the following contents, adjusting values according to your setup:DB_HOST=localhost DB_PORT=3306 DB_USER=admin DB_PASSWORD=password DB_NAME=bitcoin_analytics NODE_RPC_URL=http://<your-rpc-user>:<your-rpc-password>@localhost:8332/ IMPORTBLOCKS=true IMPORTEXCHANGERATES=true
- Run the Application: With your environment configured, you can start the application by running:
This will start the NestJS server, and the application will begin to import data from your configured Bitcoin Core node into the MySQL database. NOTE: if the
npm run dev:api
IMPORT
environment variable is set to true the application
Running locally you can now navigate to http://localhost:3000/api-docs
and open swagger page and openapi docs.
- Run the Application: With your environment configured, you can start the application by running:
This will start the NestJS server, and the application will begin connect to the configured lnd node. This service will be used to collect graph information about the lightning network.
npm run dev:lnd
Ensure that your Bitcoin Core node is fully synchronized with the blockchain before starting the import process. Depending on the blockchain size and your system's specifications, synchronization and data import might take some time.