Chromia
Start Building

02 / 07Advanced

Set up your project

Have the following prerequisites ready before you begin:

Set up PostgreSQL database

Set up PostgreSQL database

Rell needs PostgreSQL 16.3. Without it, the IDE still works, but you can't run a node. You can run a console or a remote postchain app without a database.

Rell expects these database settings by default:

  • 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 or update the Chromia CLI.

Prerequisite

Confirm the following first:

  • PostgreSQL database: Follow Set up PostgreSQL database.
  • RELL_JAVA environment: Chromia CLI needs a Java runtime, version 21 or later. The package managers handle this for you, so no manual setup is required. To choose which Java runtime runs 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 Chromia CLI Packages.

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 packages page. If you installed it with a package manager, update it with the matching command:

shell
brew updatebrew upgrade chr

Docker

With Docker, you can run an isolated Linux container that already includes the Chromia CLI. You still need the PostgreSQL database set up.

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, call docker run with the CLI image name followed by chr.

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 "$@"

Start by creating the project for your blockchain app:

  1. Generate a new project from the template with the Chromia CLI:
shell
chr create-rell-dapp order-system-example --template=plain
shell
cd order-system-example
  1. Add the ICMF library configuration below to the generated chromia.yml file:
chromia.yml
libs:  icmf:    registry: https://gitlab.com/chromaway/core/directory-chain    path: src/lib/icmf    tagOrBranch: 1.90.1    rid: x"B56524EE85B679371EAB1A069B03BE6A3E94F36993DEA900747BA5BAE8B99122"
  1. Download the library with the following command. The library lets your blockchains send messages to and receive messages from each other:
shell
chr install
  1. Put the definitions below at the top of chromia.yml. They simplify configuring chains for messaging:
chromia.yml
definitions:  - &sender # Configuration for a chain that sends messages    gtx:      modules:        - "net.postchain.d1.icmf.IcmfSenderGTXModule"  - &receiver # Base configuration for a chain that receives messages    gtx:      modules:        - "net.postchain.d1.icmf.IcmfReceiverGTXModule"    sync_ext:      - "net.postchain.d1.icmf.IcmfReceiverSynchronizationInfrastructureExtension"  - &sender_receiver # Base configuration for a chain that will both send and receive messages    gtx:      modules:        - "net.postchain.d1.icmf.IcmfSenderGTXModule"        - "net.postchain.d1.icmf.IcmfReceiverGTXModule"    sync_ext:      - "net.postchain.d1.icmf.IcmfReceiverSynchronizationInfrastructureExtension"

This defines an array of three elements, each tied to an anchor: &sender, &receiver, and &sender_receiver. Each anchor holds a configuration that a chain uses depending on whether it sends messages, receives them, or does both.

For reference, here are the project structure and the complete chromia.yml after these changes. Compare them against your own files:

Project structure

text
order-system-example/ ├── build/ ├── src/ │   ├── lib/ │   ├── test/ │   └── main.rell ├── .gitignore └── chromia.yml

Final version of the chromia.yml file

chromia.yml
definitions:  - &sender # Configuration for a chain that sends messages    gtx:      modules:        - "net.postchain.d1.icmf.IcmfSenderGTXModule"  - &receiver # Base configuration for a chain that receives messages    gtx:      modules:        - "net.postchain.d1.icmf.IcmfReceiverGTXModule"    sync_ext:      - "net.postchain.d1.icmf.IcmfReceiverSynchronizationInfrastructureExtension"  - &sender_receiver # Base configuration for a chain that will both send and receive messages    gtx:      modules:        - "net.postchain.d1.icmf.IcmfSenderGTXModule"        - "net.postchain.d1.icmf.IcmfReceiverGTXModule"    sync_ext:      - "net.postchain.d1.icmf.IcmfReceiverSynchronizationInfrastructureExtension"blockchains:  order-system-example:    module: maincompile:  rellVersion: 0.14.9database:  schema: schema_order_system_exampletest:  modules:    - testlibs:  icmf:    registry: https://gitlab.com/chromaway/core/directory-chain    path: src/messaging/icmf    tagOrBranch: 1.29.0    rid: x"19D6BC28D527E6D2239843608486A84F44EDCD244E253616F13D1C65893F35F6"

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