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 mainnet. For deployment instructions, see Deploy your dapp to mainnet.

  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. Specify URLs of Chromia nodes running the Directory chain in your client code. For the most recent and complete list, visit the Chromia Block Explorer and view the list of nodes in the system cluster.

    const directoryNodeUrlPool = [
    "https://system.chromaway.com:7740",
    "https://chromia.mainnet.validatrium.club:7740",
    "https://chromia-mainnet-systemnode-1.stakin-nodes.com:7740",
    "https://chroma.node.monster:7741",
    "https://chromia.mainnet-system.nodeops.ninja:7740",
    "https://chromia-mainnet-system.dwellir.com:443",
    "https://chromia-mainnet-1.dappradar.com:7740",
    "https://sys-main.chromia.coinhall.org:7740/",
    ];
  4. Establish a connection to your dapp by providing the dapp's Blockchain RID and the system node URLs:

    // Connection input
    const blockchainRID = "<BlockchainRID>"; // Target Blockchain RID
    const directoryNodeUrlPool = ["<TargetUrl1>", "<TargetUrl2>", "etc."]; // System node URLs

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

    Replace <BlockchainRID> with the actual blockchain RID for your dapp, and the <TargetUrls> with the appropriate Chromia system node URLs from step 3.

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.