Environment Configuration
Define a single d9Config module that all guides and examples import.
Prerequisites: A Vite + TypeScript project and the values from Mainnet Endpoints.
-
Add the following environment variables to
.env.local(or your deployment environment). For mainnet:Terminal window VITE_D9_RPC_URL=wss://rpc-hermes.d9network.comVITE_D9_GENESIS_HASH=0xc3140da27f348abd94a638e9ca7ee7e9005caf5f2b451044c9487905ea5e0991VITE_D9_RELAY_URL=wss://relay.d9network.comVITE_D9_PROJECT_ID=d9-wallet-publicVITE_D9_WALLET_SCHEME=d9wallet- Keep all values aligned to the same target network.
- Copy
VITE_D9_GENESIS_HASHfrom a trusted release configuration—never from the RPC endpoint you are about to verify. VITE_D9_PROJECT_IDcan be any non-empty string; the D9 Relay does not use it for authorization.
-
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"),}; -
Keep Vite’s
src/vite-env.d.tsso TypeScript recognizesimport.meta.env.
Verify
Section titled “Verify”Start the application. If any variable is omitted, startup throws Missing environment variable: <name>. Next, complete RPC Verification before requesting any signatures.
Configuration guidelines
Section titled “Configuration guidelines”- 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.
