Skip to main content

Connect a client

This section covers how to connect a frontend or other client to a dapp backend deployed on a Chromia network. The examples here use the TypeScript-based postchain-client, but the principles are the same when using other client libraries.

To connect to a deployed dapp, the client library needs a pool of URLs to system nodes in the Chromia network, as well as the Blockchain RID of the dapp to connect to. The client automatically queries the Directory chain on the system nodes to fetch the URLs of all nodes where your dapp is currently running, thus establishing a connection to the dapp.

  1. Ensure you have a dapp deployed on a Chromia network. This will most likely be Testnet. For deployment instructions, see Deploy your dapp to testnet.

  2. If you are deploying a frontend created using the Hello World guide, remove the admin key pair configuration and replace it with a secure link to your stored key pair. This ensures the security of your key pair. For more details on how to build a production-ready dapp, visit the Chromia course page.

    // Remove any private keys from your production client code
    const adminPubkey = Buffer.from("<PubkeyLink>", "hex");
    const adminPrivkey = Buffer.from("<PrivkeyLink>", "hex");
  3. Establish a connection to your dapp by providing the Blockchain RID and a node pool from Testnet:

    // Connection input
    const blockchainRID = "<BlockchainRID>"; // Target Blockchain RID
    const directoryNodeUrlPool = [
    "https://node0.testnet.chromia.com:7740",
    "https://node1.testnet.chromia.com:7740",
    "https://node2.testnet.chromia.com:7740",
    "https://node3.testnet.chromia.com:7740",
    ]; // Target URLs

    // Connection setup
    const chromiaClient = await pcl.createClient({
    blockchainRID,
    directoryNodeUrlPool,
    });

    Replace <BlockchainRID> with the actual blockchain RID for your dapp.

With these steps, you have successfully configured postchain-client to work with your dapp backend running on the Chromia network.

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