Skip to main content

Deploy your dapp to testnet

This topic covers deploying and updating a dapp with the Chromia CLI to the public testnet. For more information, see the deployment command.

info

For information on deploying your dapp to mainnet, see the Deploy your dapp to mainnet topic.

Prerequisite

Deploy the dapp

  1. Update chromia.yml: Copy the deployments key below into your chromia.yml configuration file. Replace <ContainerID> with the Container ID you got from the staking page.

    deployments:
    testnet: # Deployment Target name
    brid: x"6F1B061C633A992BF195850BF5AA1B6F887AEE01BB3F51251C230930FB792A92" # Blockchain RID for Testnet Directory Chain
    url: https://node0.testnet.chromia.com:7740 # Target URL for one of the nodes in Testnet
    container: <ContainerID> # Replace with your container ID (Example - container: 15ddfcb25dcb43577ab311fe78aedab14fda25757c72a787420454728fb80304)
    info

    For verification of the brid and url, follow these steps:

    • Visit the Chromia Explorer and set Current network to Testnet.
    • Under Clusters, select system.
    • Copy an API URL from the bottom of the page (e.g., https://node0.testnet.chromia.com:7740) and use it as the url.
    • Under System Chains, click directory_chain and copy the brid.
  2. Create a config file: Ensure the CLI knows which key to use by creating a configuration file.

    • Locate or create the .chromia folder in your home directory:

      • Linux/macOS: ~/.chromia/
      • Windows: C:\Users\<YourUsername>\.chromia\
    • Inside this folder, create a file named config and add the following line:

      key.id = testnet_container_key

      This assumes you named your key testnet_container_key during the key generation step. If you used a different key ID, replace testnet_container_key with your chosen key ID.

    • Verify that the generated key files (testnet_container_key and testnet_container_key.pubkey) are present in the .chromia folder. If they are missing, re-run the key generation step using the instructions in Generate a key pair.

    This file ensures the CLI uses the correct private key when deploying your dapp.

  3. Deploy your dapp: Run the deployment command.

    chr deployment create --settings chromia.yml --network testnet --blockchain hello

    By default, this command reads the keyId from the configuration file located at .chromia/config.

    • Windows: C:\Users\<YourUsername>\.chromia\config
    • macOS and Linux: /Users/<YourUsername>/.chromia/config or /home/<YourUsername>/.chromia/config

    If you prefer to use a different configuration file, you can specify the path using the --config option:

    chr deployment create --settings chromia.yml --network testnet --blockchain hello --config <config file path>

    This allows you to set the keyId in a specific config file instead of the global configuration.

    info

    If you get an error while deploying your dapp, then make some changes to your dapp code. Chromia uses dapp configuration and code to create the Blockchain RID, which must be unique for each dapp.

  4. Add the chains key to chromia.yml: After a successful deployment, you get the dapp Blockchain RID as a prompt in the terminal. It identifies your dapp for future deployments (updates). The prompt could look as follows:

    Deployment of blockchain hello was successful
    Add the following to your project settings file:
    deployments:
    testnet:
    chains:
    hello: x"<BlockchainRID>" #Dapp Blockchain RID

    Add the chains key with the dapp name: **Blockchain RID** from the prompt to the chromia.yml file. This is important for updating your dapp in the future.

Update the dapp

Once you have done your first deployment, you can perform an update of your dapp.

info

The limitations on updating Rell entities are available here.

Your chromia.yml must now have the chains config included.

blockchains:
hello:
module: main
deployments:
testnet:
brid: x"6F1B061C633A992BF195850BF5AA1B6F887AEE01BB3F51251C230930FB792A92"
url: https://node0.testnet.chromia.com:7740
container: <ContainerID>
chains:
hello: x"<BlockchainRID>" #Dapp Blockchain RID

Run the following command to update your dapp:

chr deployment update --settings chromia.yml --network testnet --blockchain hello

By default, this command reads the keyId from the configuration file located at .chromia/config.

  • Windows: C:\Users\<YourUsername>\.chromia\config
  • macOS and Linux: /Users/<YourUsername>/.chromia/config or /home/<YourUsername>/.chromia/config

If you prefer to use a different configuration file, you can specify the path using the --config option:

chr deployment update --settings chromia.yml --network testnet --blockchain hello --config config <config file path>

This allows you to set the keyId in a specific config file instead of the global configuration.

To learn more about developing production-ready dapps, visit the Chromia course page.