The reference document is running-api-from-source . Thanks to wileyj and whoabuddy for their contributions to the original document. This article is based on the above document to improve the database installation, background startup, Bitcoin node information and other details. *
In this document, we'll go over how to run a stacks-blockchain-api instance.There are several components involved here to have a working setup, and we'll go over each.Please note that the following guide is targetted for Debian based systems - that in mind, most of the commands will work on other Unix systems with some small adjustments.
PS: The following terminal interaction and output return are performed under Ubuntu 20.04 LTS
Since we'll need to create some files/dirs for persistent data,we'll first create a base directory structure and set some permissions:
Optional but recommended - If you want the V1 BNS data, there are going to be a few extra steps:
**Download the BNS data: ** curl -L https://storage.googleapis.com/blockstack-v1-migration-data/export-data.tar.gz -o /stacks-node/bns/export-data.tar.g. z
**Extract the data: ** tar -xzvf ./bns/export-data.tar.gz -C /stacks-node/bns/
Each file in ./bns will have a corresponding sha256 value.
To Verify, run a script like the following to check the sha256sum:
We'll need to set a basic role, database to store data, and a password for the role.Clearly, this password is insecure so modify password to something stronger before creating the role.
The stacks blockchain api requires several Environment Variables to be set in order to run properly.To reduce complexity, we're going to create a .env file that we'll use for these env vars.
** Note: ** to enable BNS names, uncomment BNS_IMPORT_DIR in the below .env file.
Create a new file: /stacks-node/stacks-blockchain-api/.env with the following content:
No need to stop stacks-blockchain-api unless there are special circumstances.
In order to have a usable API instance, it needs to have data from a running stacks-blockchain instance.
You will need to have the following in your Config.toml - this config block will send blockchain events to the API instance that was previously started:
Here is an example Config.toml that you can use - create this file as /stacks-node/config/Config.toml:
Download latest release binary from https://github.com/blockstack/stacks-blockchain/releases/latest
**Linux archive for latest release : **
No need to stop stacks-blockchain unless there are special circumstances.
To verfiy the database is ready: