Chromia
Start Building

02 / 06Intermediate

Set up your project

Prerequisites

  • You can write basic Python.
  • You know the core ideas behind blockchains.
  • You have a basic grasp of PySpark and Big Data processing.
  • You have Python 3.8 or later and the related libraries.
  • You work inside a Python virtual environment.

Set up the Chromia development environment

Complete the following setup steps before you start:

Set up PostgreSQL database

Set up PostgreSQL database

Rell needs PostgreSQL 16.3. You can use the IDE without a database, but you can't run a node. A console or a remote postchain app runs without a database.

By default, Rell expects these database settings:

  • database: postchain
  • user: postchain
  • password: postchain

Install

  1. Install Homebrew by following the Homebrew installation guide.

  2. Install PostgreSQL:

    shell
    brew install postgresql@16brew services start postgresql@16createuser -s postgres
  3. Create and configure the database:

    plsql
    psql -U postgres -c "CREATE DATABASE postchain WITH TEMPLATE = template0 LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8' ENCODING 'UTF-8';" -c "CREATE ROLE postchain LOGIN ENCRYPTED PASSWORD 'postchain'; GRANT ALL ON DATABASE postchain TO postchain;"
Install Chromia CLI

Install Chromia CLI

Follow these steps to install and update the Chromia CLI.

Prerequisite

Check that you have the following in place first:

  • PostgreSQL database: Follow the PostgreSQL setup guide.
  • RELL_JAVA environment: Chromia CLI runs on a Java runtime, version 21 or later. The package managers handle this dependency, so you normally don't configure it yourself. To choose a specific Java runtime for Chromia CLI, set the RELL_JAVA environment variable to the location of a valid Java installation.

Installation

Install Chromia CLI through a package manager, or download it from the Chromia CLI package registry.

On macOS, install Chromia CLI (chr) as follows:

  1. Install Homebrew if you don't have it yet:

    bash
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Register the Chromia repository with Homebrew:

    bash
    brew tap chromia/core https://gitlab.com/chromaway/core-tools/homebrew-chromia.git
  3. Install Chromia CLI:

    bash
    brew install chromia/core/chr
  4. Confirm the installation by printing the version:

    bash
    chr --version

Updating Chromia CLI

Get the newest Chromia CLI from the package registry. If a package manager installed it, update it with the command for your platform:

shell
brew updatebrew upgrade chr

Docker

You can run Chromia CLI inside a standalone Linux container where it is already installed. Set up the PostgreSQL database first.

The published images require Docker to be installed and configured on your host. The Docker documentation explains how to install Docker on Windows, Mac, and Linux.

Start the Docker container with Chromia CLI pre-installed

To run the latest Chromia CLI, pass the CLI image name and chr to the docker run command.

shell
docker run --rm -v $(pwd):/usr/app registry.gitlab.com/chromaway/core-tools/chromia-cli/chr:<latest version> chr

To update or remove the Docker image, consult the Docker command line reference.

bash
#!/bin/bash# Allocate a pseudo-TTY one when run in interactive modeif [ -t 0 ] && [ -t 1 ] ; then TTY="--tty"; else TTY=""; fidocker run \  # Sets the network to host to not need to change the database hostname (linux only)  --network=host \  # Set timezone based on system settings (linux only)  -e TZ=$(cat /etc/timezone) \  # Sets process ownership to current user  --user $(id -u):$(id -g) \  --mount type=bind,source="/etc/passwd",target=/etc/passwd,readonly \  --mount type=bind,source="/etc/group",target=/etc/group,readonly \  # Configures ssh-agent (only needed if chr install is called on non-public repositores)  -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK \  --volume "$SSH_AUTH_SOCK:$SSH_AUTH_SOCK" \  --mount type=bind,source="${HOME}/.ssh",target=${HOME}/.ssh,readonly \  --mount type=bind,source="${HOME}/.config/jgit",target=${HOME}/.config/jgit \  # Mounts current folder into the container (Use `Get-Location` on PowerShell)  --mount type=bind,source="$(pwd)",target=/usr/app \  --interactive ${TTY} \  --rm \  registry.gitlab.com/chromaway/core-tools/chromia-cli/chr:${CHR_VERSION:-latest} chr "$@"

Clone the project repository

shell
git clone https://bitbucket.org/chromawallet/big-data-spark/src/main/
shell
cd main/rell/

Install Rell dependencies

shell
chr install
shell
cd pyspark

Install PySpark dependencies

Set up a virtual environment

Linux/WSL:

shell
# Create virtual environmentpython3 -m venv venv# Activate virtual environmentsource venv/bin/activate# Install dependenciespip install -r requirements.txt

Windows:

shell
# Create virtual environmentpython -m venv venv# Activate virtual environmentvenv\Scripts\activate# Install dependenciespip install -r requirements.txt

Note: Activate your virtual environment before you run any of the project's Python scripts.

Written for this site from Chromia’s public course. Code samples are the course’s own.