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.
For information on deploying your dapp to mainnet, see the Deploy your dapp to mainnet topic.
Prerequisite
- Install Chromia CLI; see Install and configure Chromia CLI.
- Build a dapp that compiles; see Build and run the Hello World dapp with Chromia CLI.
- Container ID (follow the instructions on the Get a container for your dapp page to lease a container).
Deploy the dapp
-
Update
chromia.yml
: Copy thedeployments
key below into yourchromia.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)infoFor verification of the
brid
andurl
, 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 theurl
. - Under System Chains, click directory_chain and copy the
brid
.
-
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\
- Linux/macOS:
-
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, replacetestnet_container_key
with your chosen key ID. -
Verify that the generated key files (
testnet_container_key
andtestnet_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.
-
-
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.infoIf 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.
- Windows:
-
Add the
chains
key tochromia.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 RIDAdd the
chains
key with thedapp name: **Blockchain RID**
from the prompt to thechromia.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.
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.