Configure client and deploy your dapp to Testnet
This topic covers configuring your client and deploying and updating a dapp with the Chromia CLI to the public Testnet.
Configure client for Testnet
You can use the postchain-client with a dapp backend running on the Chromia network by setting up a connection to the Directory chain. Every blockchain connects to the Directory chain, read more here. Through the Directory chain connection, the client finds all the addresses where your dapp is currently running and establishes a connection encountering the list of addresses.
If you're configuring your client for the public Chromia network, use the following Directory chain node URL as the
chromiaD1blockchainRID variable below:
const chromiaD1Url = "https://testnet2.chromia.dev:7740";
const chromiaD1blockchainRID = "8C5AB44B61934386D00A446D264810E19B3B8C0E28DF6CFF54966E7814BDCD11";
For the current network of Chromia, there is only one node using HTTPS (https://testnet2.chromia.dev:7740). Therefore, if you are hosting your front end using HTTPS, you must configure your client to only connect to that single node. Skip the following section and use the previous example, substituting the above node URL.
To make this possible, you need a dapp. For more information, see Deploy your dapp to Testnet.
- Remove the local key pair in the client code (configured for a local setup). Instead, link to your key pair stored somewhere secure. For more information, see Deploy your dapp to Testnet.
const adminPubkey = Buffer.from("<PubkeyLink>", "hex");
const adminPrivkey = Buffer.from("<PrivkeyLink>", "hex");
To connect to the Chromia network, specify a URL and a Blockchain RID of a Chromia node running the Directory chain in the client code file.
The REST Client is then configured for the specific Chromia base URL and Blockchain RID. It's followed by an instance of a Chromia Client provider. It uses the REST Client instance and allows calls to the Directory chain.
After that, you can set a connection with a blockchain of the dapp Blockchain RID. It returns a REST Client with the addresses of the nodes that run your blockchain.
- In the client code file (configured for a local setup), replace the following part
const nodeApiUrl = "http://localhost:7740/"; //Using default postchain node REST API port
const blockchainRID = "<BlockchainRID>"; //Dapp Blockchain RID
const rest = pcl.restClient.createRestClient([nodeApiUrl], blockchainRID); //REST Client connection
with this part.
const chromiaD1blockchainRID = "<BlockchainRID>"; //Target Blockchain RID
const chromiaD1Url = "<TargetUrl>"; //Target URL
const restD1 = pcl.restClient.createRestClient(
); //REST Client connection
const chromiaClient = pcl.chromiaClient.chromiaClientProvider(
); //Chromia Client provider
const dappBlockchainRID = "<BlockchainRID>"; //Dapp Blockchain RID
const rest = await chromiaClient.blockchainConnection(dappBlockchainRID); //Blockchain connection
chromiaD1blockchainRIDwith the URL and the Blockchain RID of a Chromia node running the Directory chain. Also, replace
dappBlockchainRIDwith your dapp Blockchain RID.
You can now use the blockchain connection to initialize a gtx client
const gtx = pcl.gtxClient.createClient(rest, blockchainRID, ["set_name"]); //gtx Client connection
With these steps, you are ready to use the postchain-client with a dapp backend running on the Chromia network.
Deploy your dapp to Testnet
Now, you can deploy and update your dapp with the Chromia CLI to the public Testnet. For more information, see deployment command.
- 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.
Deploy the dapp
The important files for the deployment of a dapp are as follows:
- Project config file (
- Secrets file (contains your
Begin with generating a public and private key pair that's available in a
- Write the following command to create a
.secretfile with a generated key pair (
chr keygen --save .secret
You find the public and private key in the created
.secret file. You can copy and share the public key, while the private key should be kept as a secret in the
#Keypair generated using...
Once you have your key pair, you need to stake Chroma token to deploy a dapp to the current testnet.
- To stake Chroma token, follow the instructions on the Staking Page. Once you stake a minimum of 100 CHR, you can request a container ID. You need to use this container ID to deploy your dapp in the following example.
The current public testnet has limited capacity; therefore, it requires staking. This might change as we increase the capacity of the testnet.
Once you receive the container ID, the container gets deleted from the network unless you deploy a dapp within 48 hours. If that happens, you can return to the staking page and request a new container ID if there is still capacity.
Note that this is a testnet; data may not persist between testnet updates.
- Copy the
deploymentskey in the
config.ymlfile example below into your config file. Replace the
<ContainerID>with the Container ID you got from the staking page.
hello: #Name of the blockchain
module: main #Entrypoint to the project
testnet: #Deployment Target name
brid: x"8C5AB44B61934386D00A446D264810E19B3B8C0E28DF6CFF54966E7814BDCD11" #Blockchain RID for the testnet management chain
url: https://testnet2.chromia.dev:7740 #Target URL for one of the nodes in the testnet
container: <ContainerID> #Container ID
- Write the following command to deploy a specific chain to a specific target.
chr deployment create --settings config.yml --network testnet --blockchain hello --secret .secret
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.
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.
Add the following to your project settings file
hello: x"<BlockchainRID>" #Dapp Blockchain RID
- Add the
chainskey with the dapp name: Blockchain RID from the prompt to the
config.ymlfile. This is important for updating your dapp in the future.
Great. You have now done your first deployment. Please see the section Configure Client for Chromia Network if you want to configure the client code to connect to your deployed dapp.
Update the dapp
Once you have done your first deployment, you can perform an update of your dapp.
config.yml must now have the
chains config included.
hello: x"<BlockchainRID>" #Dapp Blockchain RID
- Write the following command to update your dapp:
chr deployment update --settings config.yml --network testnet --blockchain hello --secret .secret
When updating a dapp, you use the same command as for deployment but with the dapp Blockchain RID included in the
config.yml file. You aren't prompted with anything this time, but a snapshot file gets created, which is also the case for deployment.