Skip to content

Environment Configuration

Define a single d9Config module that all guides and examples import.

Prerequisites: A Vite + TypeScript project and the values from Mainnet Endpoints.

  1. Add the following environment variables to .env.local (or your deployment environment). For mainnet:

    Terminal window
    VITE_D9_RPC_URL=wss://rpc-hermes.d9network.com
    VITE_D9_GENESIS_HASH=0xc3140da27f348abd94a638e9ca7ee7e9005caf5f2b451044c9487905ea5e0991
    VITE_D9_RELAY_URL=wss://relay.d9network.com
    VITE_D9_PROJECT_ID=d9-wallet-public
    VITE_D9_WALLET_SCHEME=d9wallet
    • Keep all values aligned to the same target network.
    • Copy VITE_D9_GENESIS_HASH from a trusted release configuration—never from the RPC endpoint you are about to verify.
    • VITE_D9_PROJECT_ID can be any non-empty string; the D9 Relay does not use it for authorization.
  2. Create src/config.ts:

    function required(name: string): string {
    const value = import.meta.env[name]?.trim();
    if (!value) throw new Error(`Missing environment variable: ${name}`);
    return value;
    }
    export const d9Config = {
    rpcUrl: required("VITE_D9_RPC_URL"),
    expectedGenesisHash: required("VITE_D9_GENESIS_HASH"),
    relayUrl: required("VITE_D9_RELAY_URL"),
    projectId: required("VITE_D9_PROJECT_ID"),
    walletScheme: required("VITE_D9_WALLET_SCHEME"),
    };
  3. Keep Vite’s src/vite-env.d.ts so TypeScript recognizes import.meta.env.

Start the application. If any variable is omitted, startup throws Missing environment variable: <name>. Next, complete RPC Verification before requesting any signatures.

  • After verifying the genesis hash, read runtime versions, metadata, asset precision, fee parameters, reserve thresholds, locks, and cooldowns directly from the chain. Pin related queries to a single finalized block.
  • Import the wallet protocol chain ID from @d9-network/dapp-connector/protocol. It does not select the network or replace genesis hash verification.

For wallet initialization options, see Connector API.