Hope

Docs

Smart RPC

Browser-side Hope RPC with dual mirrors, rpc-pool peers, and LCD failover via @hopenetwork/smart-rpc.

Hope testnet public infrastructure has two HTTPS mirrors (gateway + validator1 edge) and a published rpc-pool.json list of incentive peers. Browsers should not hardcode a single test-gateway URL for every read.

Use @hopenetwork/smart-rpc in Vite/React apps. Hope first-party sites (Explorer, DEX, Platform, Browser Node, Poker demo) bootstrap it at startup.

Install

npm install @hopenetwork/smart-rpc

Call once before rendering your app. Dev uses your Vite proxy (/rpc, /api). Production resolves a healthy RPC base (mirrors + pool) unless you pin env vars.

import { bootstrapHopeTestnetEndpoints } from '@hopenetwork/smart-rpc';

const { rpcBaseUrl, apiBaseUrl } = await bootstrapHopeTestnetEndpoints({
  dev: import.meta.env.DEV,
  rpcBaseUrl: import.meta.env.VITE_RPC_BASE_URL,
  apiBaseUrl: import.meta.env.VITE_API_BASE_URL,
});

Wire rpcBaseUrl / apiBaseUrl into Keplr suggestChain, CosmJS SigningStargateClient, and your REST fetch helpers.

EnvBehavior
import.meta.env.DEVSame-origin /rpc and /api (proxy to gateway)
VITE_RPC_BASE_URL setPin RPC; skip smart resolution
Neither (production)HOPE_TESTNET_SMART_RPC preset: dual mirrors + pool

LCD mirror retry

For hand-rolled fetch to the REST API, retry the secondary mirror when the primary fails:

import { hopeTestnetApiMirrors } from '@hopenetwork/smart-rpc';

const bases = hopeTestnetApiMirrors(import.meta.env.VITE_API_BASE_URL);
for (const base of bases) {
  const res = await fetch(`${base}/cosmos/bank/v1beta1/supply`);
  if (res.ok) return res.json();
}

Long-lived client (rotation + cache)

For dashboards that need ongoing health checks and JSON-RPC failover:

import { HopeSmartRpcClient, HOPE_TESTNET_SMART_RPC } from '@hopenetwork/smart-rpc';

const client = new HopeSmartRpcClient({
  ...HOPE_TESTNET_SMART_RPC,
  pollIntervalMs: 8000,
});
await client.start();
const status = await client.rpc('status');

Lag and diverged (health UI)

When HopeSmartRpcClient polls endpoints, it compares each peer to a reference (tallest reachable block height this round):

LabelMeaning
LagBlocks behind reference (reference − endpoint). A few blocks is normal sync delay. Reads skip endpoints with lag > 100 by default (lagBlockThreshold).
DivergedHeights are close (within ~15 blocks) but app hash ≠ reference — unsafe data; not used for reads.
PreferredHealthy endpoint chosen for client.rpc() (sticky among top peers).

Gateway and pool peer rows are HTTPS mirrors (test-gateway, test-rpc-2, /rpc/pool/…). They are separate from the optional browser relay mesh below.

Browser relay mesh (optional, 0.4+)

Volunteer tabs serve read-only JSON-RPC through a relay WebSocket shipped with @hopenetwork/smart-rpc (npm run relay). Deploy behind nginx on both mirrors at /browser-relay/v1.

Consumers must use createHopeTestnetSmartRpcClient (or HopeSmartRpcClient + client.rpc()). One-shot bootstrapHopeTestnetEndpoints() does not use the mesh.

import {
  createHopeTestnetSmartRpcClient,
  browserRelayFromViteEnv,
} from '@hopenetwork/smart-rpc';

const client = await createHopeTestnetSmartRpcClient({
  dev: import.meta.env.DEV,
  browserRelay: browserRelayFromViteEnv(import.meta.env),
});
await client.rpc('status');
EnvPurpose
VITE_BROWSER_RELAY_ENABLED=trueOpt in
VITE_BROWSER_RELAY_URLRelay WebSocket (dev: ws://127.0.0.1:8787)
VITE_BROWSER_RELAY_MODEfallback (default), prefer_mesh, off

Dapps without browserRelay behave as 0.2.x (HTTPS mirrors + pool only). fallback keeps mirror traffic first; mesh runs when mirrors fail. Contributors cache and rate-limit upstream gateway calls.

Mirrors and pool (reference)

ResourcePrimaryMirror B
RPChttps://test-gateway.hopenetwork.io/rpchttps://test-rpc-2.hopenetwork.io/rpc
LCDhttps://test-gateway.hopenetwork.io/apihttps://test-rpc-2.hopenetwork.io/api
Pool JSON…/rpc-pool.json on each mirror

Peer browser traffic is proxied at https://<mirror>/rpc/pool/{pool_key}/… (CORS-enabled). Native nodes use the peer url field directly — see Run a node and hope-node-public public RPC.

CometBFT POST URL

JSON-RPC POST must target /rpc/ (trailing slash). GET paths such as /rpc/status work without it. Hope HTTP clients in Explorer/DEX add the slash for jsonRpc calls automatically.

When not to use Smart RPC

  • Server-side indexers, relayers, and CI should use env HOPE_RPC / HOPE_LCD or a local node — not IndexedDB or browser pool logic.

See also Network for chain ID, genesis, and Keplr chain info.

On this page