# Set up your project · Your first Rell app on Chromia · Learn Chromia

> Set up the following prerequisites before you begin:

Source: https://chromia.com/learn/book-review/setup/

Your first Rell app on ChromiaLesson 2 of 26

1. [01Your first Rell app on Chromia](https://chromia.com/learn/book-review/introduction/)
2. [02Set up your project](https://chromia.com/learn/book-review/setup/)
3. [03Rell project structure](https://chromia.com/learn/book-review/rell-structure/)

Part 1: Define your first entity

1. [04Overview](https://chromia.com/learn/book-review/book-entity/)
2. [05Create your first entity](https://chromia.com/learn/book-review/book-entity/tables/)
3. [06Add your first operation](https://chromia.com/learn/book-review/book-entity/basic-operations/)
4. [07Query every book](https://chromia.com/learn/book-review/book-entity/write-queries/)

Part 2: Add a related entity

1. [08Overview](https://chromia.com/learn/book-review/book-review-entity/)
2. [09Define the book review entity](https://chromia.com/learn/book-review/book-review-entity/tables/)
3. [10Add an operation for creating book reviews](https://chromia.com/learn/book-review/book-review-entity/basic-operations/)
4. [11Query all reviews for a book](https://chromia.com/learn/book-review/book-review-entity/write-queries/)

Part 3: Checking and validating inputs

1. [12Overview](https://chromia.com/learn/book-review/input-verification/)
2. [13Verify inputs](https://chromia.com/learn/book-review/input-verification/input-verification/)
3. [14Return structured results from queries](https://chromia.com/learn/book-review/input-verification/structure/)

Part 4: Signing transactions and filtering queries

1. [15Overview](https://chromia.com/learn/book-review/sign-transaction/)
2. [16Sign a transaction](https://chromia.com/learn/book-review/sign-transaction/sign-transaction/)
3. [17Filter and sort query results](https://chromia.com/learn/book-review/sign-transaction/structure/)

Part 5: Blockchain state and transactions explained

1. [18Overview](https://chromia.com/learn/book-review/blockchain-transactions/)
2. [19How blockchain state and transactions work](https://chromia.com/learn/book-review/blockchain-transactions/query-transaction/)
3. [20Walking through an example](https://chromia.com/learn/book-review/blockchain-transactions/example/)

Part 6: Create the client

1. [21Overview](https://chromia.com/learn/book-review/build-client/)
2. [22Prerequisites](https://chromia.com/learn/book-review/build-client/prerequisites/)
3. [23Establishing a connection to Chromia](https://chromia.com/learn/book-review/build-client/sign-transaction/)
4. [24Query the blockchain using postchain-client](https://chromia.com/learn/book-review/build-client/query-blockchain/)
5. [25Complete the example](https://chromia.com/learn/book-review/build-client/complete-example/)

1. [26What’s next?](https://chromia.com/learn/book-review/what-next/)

[Learn](https://chromia.com/learn/)[Your first Rell app on Chromia](https://chromia.com/learn/book-review/)

02 / 26Beginner

# Set up your project

Set up the following prerequisites before you begin:

Set up PostgreSQL database

## Set up 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 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](https://brew.sh/).
2. Install PostgreSQL:

   shell

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

   plsql

   ```nolines
   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;"
   ```

   note

   A "peer authentication failed" error means you need to switch the authentication method from `peer` to `md5`. Make this change in the `pg_hba.conf` file of your `psql` database.

1. Install PostgreSQL:

   bash

   ```nolines
   sudo apt install postgresql-16
   ```
2. Create and configure the database:

   bash

   ```nolines
   sudo -u postgres psql -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;"
   ```

1. Install Docker by following the [Docker installation guide](https://docs.docker.com/engine/install/).
2. Create and configure the database:

   dockerfile

   ```nolines
   docker run --name postgres -e POSTGRES_USER=postchain -e POSTGRES_PASSWORD=postchain -p 5432:5432 -d postgres:16.3-alpine3.20
   ```

   note

   The Alpine image of PostgreSQL is used here because its default collation settings are the ones Rell needs. You can also set the collation explicitly with an environment variable:

   bash

   ```nolines
   POSTGRES_INITDB_ARGS="--lc-collate=C.UTF-8 --lc-ctype=C.UTF-8 --encoding=UTF-8"
   ```

1. Get the PostgreSQL installer from the [PostgreSQL website](https://www.postgresql.org/download/windows/).
2. Run the installer, then add the PostgreSQL binaries folder to your environment variables. In Command Prompt (CMD), run the command below. Check that the path points to your binaries and swap the `<version>` placeholder for your installed version number:

   shell

   ```nolines
   setx POSTGRESQL "C:\Program Files\PostgreSQL\<version>\bin"
   ```
3. Close and reopen Command Prompt (CMD) so the new environment variables take effect. Then run these two commands, one after the other, to create and configure the database:

   plsql

   ```nolines
   psql -U postgres -c "CREATE DATABASE postchain WITH TEMPLATE = template0 LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' ENCODING 'UTF-8';"
   psql -U postgres -c "CREATE ROLE postchain LOGIN ENCRYPTED PASSWORD 'postchain'; GRANT ALL ON DATABASE postchain TO postchain;"
   ```

   note

   Some Windows versions produce permission errors or broken PostgreSQL installations. If you run into these, install Docker and run PostgreSQL as a container instead.

Install Chromia CLI

## Install Chromia CLI

Follow these steps to install and update the [Chromia CLI](https://gitlab.com/chromaway/core-tools/chromia-cli).

## Prerequisite

You need the following in place first:

* **PostgreSQL database**: Follow [Set up PostgreSQL database](https://docs.chromia.com/get-started/installation/#set-up-postgresql-database).
* **RELL\_JAVA environment**: Chromia CLI runs on a Java runtime, version 21 or later. The package managers handle this dependency for you, so no manual setup is needed. To choose a specific Java runtime for Chromia CLI, set the RELL\_JAVA environment variable to the path of a valid Java installation.

## Installation

Install Chromia CLI through a package manager, or download it from [Chromia CLI Packages](https://gitlab.com/chromaway/core-tools/chromia-cli/-/packages).

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

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

   bash

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

   bash

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

   bash

   ```nolines
   brew install chromia/core/chr
   ```

   info

   To pin a particular Chromia CLI version, run:

   shell

   ```
   brew install chromia/core/chr@<version>
   brew unlink chr
   brew link chr@<version>
   ```

   To see which versions are available, run `brew search chr`.
4. Confirm the installation by printing the version:

   bash

   ```nolines
   chr --version
   ```

On Linux or WSL (Windows Subsystem for Linux), install Chromia CLI (`chr`) as follows:

1. Download Chromia's `apt-repo` public key and add it to your trusted keyrings:

   bash

   ```nolines
   curl -fsSL https://apt.chromia.com/chromia.gpg | sudo tee /usr/share/keyrings/chromia.gpg
   ```
2. Add the Chromia repository to your package sources:

   bash

   ```nolines
   echo "deb [arch=amd64 signed-by=/usr/share/keyrings/chromia.gpg] https://apt.chromia.com stable main" | sudo tee /etc/apt/sources.list.d/chromia.list
   ```
3. Refresh your package sources:

   bash

   ```nolines
   sudo apt-get update
   ```

   info

   If you added `apt.chromia.com` before Chromia CLI version `0.16.0`, run this command so the repository update is allowed:

   bash

   ```nolines
   sudo apt-get --allow-releaseinfo-change update
   ```
4. After the update finishes, install Chromia CLI:

   bash

   ```nolines
   sudo apt-get install chr
   ```
5. Confirm the installation by printing the version:

   bash

   ```nolines
   chr --version
   ```

On Windows, install Chromia CLI (`chr`) with [Scoop](https://scoop.sh/) as follows:

1. Install Scoop if you don't have it yet. Run this in PowerShell as Administrator:

   powershell

   ```nolines
   iwr -useb get.scoop.sh | iex
   ```
2. Add the Chromia bucket to Scoop:

   powershell

   ```nolines
   scoop bucket add chromia https://gitlab.com/chromaway/core-tools/scoop-chromia/
   ```
3. Add the Java bucket to Scoop:

   powershell

   ```nolines
   scoop bucket add java
   ```

   Scoop needs this bucket to fetch openjdk21, which chromia-cli depends on during installation.
4. Install Chromia CLI:

   powershell

   ```nolines
   scoop install chr
   ```
5. Confirm the installation by printing the version:

   powershell

   ```nolines
   chr --version
   ```

## Updating Chromia CLI

Download the latest Chromia CLI from [the packages page](https://gitlab.com/chromaway/core-tools/chromia-cli/-/packages). If you installed it with a package manager, update it with the command for your platform:

shell

```nolines
brew update
brew upgrade chr
```

shell

```nolines
sudo apt-get update
sudo apt-get install chr
```

shell

```nolines
scoop update
scoop update chr
```

## Docker

With Docker, you can run a self-contained Linux container that already includes the Chromia CLI. You still need the [PostgreSQL database](https://docs.chromia.com/get-started/installation/#set-up-postgresql-database) set up.

The published images require Docker to be installed and configured on your host. For Windows, Mac, and Linux instructions, see [install Docker](https://docs.docker.com/get-docker/) in the Docker documentation.

### Start the Docker container with Chromia CLI pre-installed

To run the newest Chromia CLI, pass the CLI image name and `chr` to `docker run`.

shell

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

Windows Command Prompt Users

Windows Command Prompt (cmd) does not understand the `$(pwd)` syntax. Use one of these instead:

* **PowerShell**: `$(Get-Location)` or `$(pwd)`
* **Command Prompt**: `%CD%`

**Command Prompt example:**

cmd

```nolines
docker run --rm -v %CD%:/usr/app registry.gitlab.com/chromaway/core-tools/chromia-cli/chr:<latest version> chr
```

note

Set up your `chromia.yml` file for your platform:

* **Mac**: Set `database:host` to `host.docker.internal`.
* **Windows**: Set `database:host` to `host.docker.internal` (Docker Desktop). If the node still cannot reach your database, try `172.17.0.1`, the default Docker bridge address on Linux.
* **Linux**: Add the `--network=host` argument to your Docker commands.

Without these settings, Chromia CLI cannot reach the PostgreSQL instance.

For updating or removing the Docker image, see the [Docker command line reference](https://docs.docker.com/engine/reference/commandline/docker/).

bash

```
#!/bin/bash

# Allocate a pseudo-TTY one when run in interactive mode
if [ -t 0 ] && [ -t 1 ] ; then TTY="--tty"; else TTY=""; fi

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

Windows Command Prompt Users

This bash script relies on `$(pwd)`, which Windows Command Prompt does not support. On Windows:

* **PowerShell**: run the command unchanged; PowerShell also understands `$(pwd)`.
* **Command Prompt**: In the mount command, change `$(pwd)` to `%CD%`.

**Mount line adjusted for Command Prompt:**

cmd

```nolines
--mount type=bind,source="%CD%",target=/usr/app \
```

Start by creating your blockchain app project with the Chromia CLI.

shell

```nolines
chr create-rell-dapp book-review --template=plain
```

shell

```nolines
cd book-review
```

The command creates the core project files and configuration you need.

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

[← Previous**Your first Rell app on Chromia**](https://chromia.com/learn/book-review/introduction/)[Next →**Rell project structure**](https://chromia.com/learn/book-review/rell-structure/)

On this page

* [Install](#install)
* [Prerequisite](#prerequisite)
* [Installation](#installation)
* [Updating Chromia CLI](#updating-chromia-cli)
* [Docker](#docker)
