Hive Developer logo

Hive Developer Portal

Using Hivemind

Hivemind setup and API functionality

Intro

Hivemind is a “consensus interpretation” layer for the Hive blockchain, maintaining the state of social features such as post feeds, follows, and communities. Written in Python, it synchronizes an SQL database with chain state, providing developers with a more flexible/extensible alternative to the raw hived API. This means that you can bypass hived and access data in a more traditional way, for example, with SQL. But you can’t use SQL on hived. So Hivemind solves that problem. Hivemind does not support any queries to do with wallets, orders, escrow, keys, recovery, or account history.

Supported API functionality:

Core API set available in Hivemind:

Also see non-hived methods backed by Hivemind: bridge

Additional functions available within hivemind library

The majority of these functions are reliant on hived so any changes to hived would affect these function calls. The only two functions not directly reliant on hived are stream_blocks and get_hive_per_mvest.

Detailed information on the Hivemind library can be found in the Hivemind repo.

Hivemind dependencies and setup

If you would prefer to install Hivemind yourself you can do so following the basic instructions below.

This setup can be performed on an Ubuntu server.

There are two dependencies for setting up the dev environment on ubuntu for running Hivemind:

$ sudo apt-get update
$ sudo apt-get install python3 python3-pip
$ sudo apt-get install postgresql

More detailed documentation on the setup of Hivemind can be found at the Hivemind github repository.

Once the dependencies have been installed the database can be created and the environment variables set.

$ sudo service postgresql start
$ su - postgres -c "psql -c \"ALTER USER postgres WITH PASSWORD 'postgres';\""
$ su - postgres -c "createdb hive"
$ su - postgres -c "psql -d hive -c \"CREATE EXTENSION intarray;\""
$ export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/hive
$ export PG_PASSWORD=postgres
$ sudo service postgresql restart
Installation
$ git clone https://gitlab.syncad.com/hive/hivemind.git
$ cd hivemind
$ git submodule update --init --recursive
$ python3 setup.py build
$ sudo pip3 install jinja2
$ sudo python3 setup.py install

By default Hivemind will connect to the mainnet https://api.hive.blog but if required you can change this to connect to a testnet. To do this set the environment variable as described below.

# Note as of 2021-05-14, Hivemind still internally uses the environment variable called STEEMD_URL for this.
$ export STEEMD_URL='http://127.0.0.1:8091'

Now that the basic setup is done you are able to sync the database.

$ hive sync

Note: Do not use a public node to hive sync. Instead of doing an initial sync, you can use a data dump, to speed up the process: Daily Hivemind backups :: How to restore

# Assunes 8 cpu cores:
$ pg_restore -j 8 -U postgres -d hive path/to/dump_file.dump
$ hive sync

You can also check the status of your synced database.

$ hive status

Once the synchronization is complete you can start the Hivemind server which will allow you to start performing queries on your local database.

$ hive server

By default the server is available on http://0.0.0.0:8080, this can also be changed by adding an environment variable.

$ export HTTP_SERVER_PORT=8090