Skip to main content

Build and run the Hello World dapp

In this topic, you'll build and deploy the Hello World dapp with the Chromia Command-line Interface (Chromia CLI). Read more about the features of the Chromia CLI in the Chromia CLI command reference section.

Prerequisite

Run dapp in VS Code

The extension enables language features for Rell, including syntax highlighting and compilation warnings. It contributes the commands Rell: New Template Project and Rell: Invalidate index caches, which are available in the Command Palette. Once you install the extension, it's time to create a project.

  1. Open the Command Palette by going to the menu View - Command Palette. Type Rell: New Template Project.

    project template
  2. The command Rell: New Template Project asks you to select the project type from the dropdown menu. Select Minimal.

    project template selection minimal
  3. Next, you get my-rell-dapp as prefilled project name. Press Enter to create the project.

    project name

    It creates a new Rell structured project with the necessary files. A main.rell file, which includes the Hello World query and test files in the src/test/ folder. You also have a standard configuration for your project in the chromia.yml file. For more information, see the project config file.

    project folder
    note

    Make sure to set the same password and username as your database instance if you didn't choose the default one from Set up PostgreSQL database. You can change this under the database attributes in the project config file.

  4. Use the Node start command to start the node.

    node start
    info

    This command starts a node that contains your app. For more information, see Deploy your dapp to testnet or node command.

    Locate the Blockchain RID in the terminal output. You need it to interact with your dapp. The Blockchain RID is the hex value following the Blockchain RID: tag. For example, see the following image.

    blockchain RID VS

    The last step is to query your dapp and test that the backend is working correctly.

  5. Write the following command in a new terminal with your project folder as the working directory. Remember to replace the <BlockchainRID> with your Blockchain RID from the node output.

    curl -X GET 'localhost:7740/query/<BlockchainRID>?type=hello_world'
  6. The CURL command requires the blockchain on localhost and port 7740, which are the standard settings. It also calls the Hello World query in the main.rell file. Your terminal should show you the following message.

    "Hello World!"
    info

    Writing CURL commands to query your backend is a safe approach, but for future queries, you might want use the query command in the Chromia CLI.

Great job. The Rell backend is up and running and works as it should. You have now run a Hello World dapp in VS Code.

Run dapp in Chromia CLI

Once you install the Chromia CLI, it's time to create a project.

  1. Create the project folder in a path of your choice and use the chr create-rell-dapp command.

    chr create-rell-dapp

    The chr create-rell-dapp command creates a new Rell structured project my-rell-dapp with the necessary files. A main.rell file, which includes the Hello World query and test files in the src/test/ folder. You also have a standard configuration for your project in the chromia.yml file. For more information, see the project config file.

    my-rell-dapp
    |--chromia.yml
    |--_src
    |--main.rell
    |--_test
    |--arithmetic_test.rell
    |--data_test.rell

    The next step is to start a node and run your app locally. You can do it in a couple of different ways, but the most straightforward method we recommend is the Chromia CLI.

  2. Use the chr node start command to start a node. Make sure it's available in the same working directory where you have the chromia.yml file.

    chr node start

    The chr node start command starts a node with your applications running on it. All the blockchains listed in the blockchains key in the chromia.yml file get started.

    blockchains:
    hello: <----- This is the blockchain that starts
    module: main <----- This is the entry point of the chain
    note

    If you are running the node on a different URL than the default http://localhost:7740, you can use the --api-url to specify it.

    Now the node should be up, where the Rell backend is running with a local blockchain. Locate the Blockchain RID in the output of the node. You need it to interact with your dapp. The Blockchain RID is the hex value following the Blockchain RID: tag. For example, see the following image.

    blockchain RID CLI

    The last step is to query your dapp and test that the backend works correctly.

  3. Write the following in a new terminal with your project folder as the working directory. Remember to replace the <BlockchainRID> with your Blockchain RID from the node output.

    chr query --blockchain-rid <BlockchainRID> hello_world
  4. Your terminal should show you the following message.

    "Hello World!"

Great job. The Rell backend is up and running and works as it should. You have now run a Hello World dapp in the Chromia CLI.

For your next steps with Rell, feel free to follow the courses on the Chromia learning platform.