Skip to content

RPC Verification

Confirm that your RPC endpoint serves D9 Mainnet before reading state or signing transactions, then generate typed PAPI 3 descriptors.

Prerequisites: src/config.ts from Environment Configuration.

Run this check before using an RPC endpoint:

import { d9Config } from "./config";
const socket = new WebSocket(d9Config.rpcUrl);
socket.onopen = () => {
// Genesis hash
socket.send(JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "chain_getBlockHash",
params: [0]
}));
// Token symbol and decimals
socket.send(JSON.stringify({
jsonrpc: "2.0",
id: 2,
method: "system_properties",
params: []
}));
};
socket.onmessage = ({ data }) => {
const response = JSON.parse(String(data));
if (response.id === 1) {
if (response.result !== d9Config.expectedGenesisHash) {
console.error("Genesis mismatch, rejecting RPC:", response.result);
socket.close();
return;
}
console.log("Verified genesis hash:", response.result);
} else if (response.id === 2) {
console.log("Chain properties:", response.result);
}
};

Verify: The console prints Verified genesis hash: followed by your configured hash.

Re-verify the genesis hash before every transaction signature request.

  1. Call chain_getFinalizedHead.
  2. Pass the returned block hash as at to every related state_getStorage and state_call request.

Without pinning to a single finalized block, quotes, reserves, and fee estimates may reflect different chain states.

  1. Export the verified RPC URL in your shell. The PAPI CLI does not read Vite’s .env files.

    Terminal window
    export VITE_D9_RPC_URL=wss://rpc-hermes.d9network.com # Verified in step 1
  2. In your DApp project directory, run:

    Terminal window
    npm install --save-exact polkadot-api@3.3.0 @d9-network/dapp-connector@0.2.0 effect@4.0.5
    : "${VITE_D9_RPC_URL:?Export the verified VITE_D9_RPC_URL first}"
    npx papi add d9 -w "$VITE_D9_RPC_URL"
    npx papi generate
  3. Commit the generated .papi configuration and metadata files to version control.

  4. After any reviewed runtime upgrade, re-run npx papi generate. Keep the same polkadot-api version for both code generation and runtime execution.

Verify: A local @polkadot-api/descriptors package is created and exports d9 and getMetadata.

Error Resolution
Genesis mismatch, rejecting RPC Switch to another RPC from Mainnet Endpoints and verify VITE_D9_GENESIS_HASH.
Export the verified VITE_D9_RPC_URL first Run the export command from step 3.1 in the same shell session.