Chromia
Start Building

02 / 06Intermediate

Set up your project

You need the following in place before you begin:

Set up a PostgreSQL database

Set up a PostgreSQL database

Rell needs PostgreSQL 16.3. You can use the IDE without a database, but you cannot run a node from it. A console or a remote postchain app does not need a database.

Rell expects these database settings by default:

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

Install

  1. Install Homebrew by following the Homebrew setup instructions.

  2. Install PostgreSQL:

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

    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 the Chromia CLI

Install the Chromia CLI

The steps below show how to install and update the Chromia CLI.

Prerequisite

Check that you have the following before you continue:

  • PostgreSQL database: Follow Set up a PostgreSQL database.
  • RELL_JAVA environment: The Chromia CLI needs a Java runtime, version 21 or later. The package managers take care of this, so you normally don't have to configure it. To choose which Java runtime runs the Chromia CLI, set the RELL_JAVA environment variable to a valid Java installation.

Installation

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

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

  1. If you don't have Homebrew yet, install it:

    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 the Chromia CLI:

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

    bash
    chr --version

Updating Chromia CLI

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

shell
brew updatebrew upgrade chr

Docker

With Docker, you can run a self-contained Linux container that already includes the Chromia CLI. You still need a PostgreSQL database set up.

The published images require Docker to be installed and configured on your host. The Docker documentation explains how to get 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 CLI 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. Make a new project directory and switch to it in your terminal:
shell
chr create-rell-dapp digital_warehouse_example --template=plain
shell
cd digital_warehouse_example
  1. Set up the ICCF library by adding this configuration to chromia.yml:
yaml
libs:  iccf:    registry: https://gitlab.com/chromaway/core/directory-chain    path: src/lib/iccf    tagOrBranch: 1.87.0    rid: x"9C359787B75927733034EA1CEE74EEC8829D2907E4FC94790B5E9ABE4396575D"  iccf_test:    registry: https://gitlab.com/chromaway/core/directory-chain    path: src/lib/test/iccf    tagOrBranch: 1.87.0    rid: x"873D71557531E35E453587FA71C2D3CCB674F0EB49D18B30FA838C52C1155EB3"

Then run chr install to fetch the iccf library, which you need for confirming transactions.

For reference, here are the project structure and the full chromia.yml file after these changes. Compare them with your own to spot differences:

Project structure

text
digital_warehouse_example/├── build/├── src/│   ├── lib/│   ├── test/│   └── main.rell├── .gitignore└── chromia.yml

Final version of the chromia.yml file

text
yaml title="chromia.yml"blockchains:  digital_warehouse_example:    module: maincompile:  rellVersion: 0.14.9database:  schema: schema_digital_warehouse_exampletest:  modules:    - testlibs:  iccf:    registry: https://gitlab.com/chromaway/core/directory-chain    path: src/lib/iccf    tagOrBranch: 1.87.0    rid: x"9C359787B75927733034EA1CEE74EEC8829D2907E4FC94790B5E9ABE4396575D"  iccf_test:    registry: https://gitlab.com/chromaway/core/directory-chain    path: src/lib/test/iccf    tagOrBranch: 1.87.0    rid: x"873D71557531E35E453587FA71C2D3CCB674F0EB49D18B30FA838C52C1155EB3"

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