Skip to content

feat(web,react): derive the RPC endpoint from the client#212

Open
WiktorStarczewski wants to merge 4 commits into
nextfrom
wiktor/rpc-endpoint-derive
Open

feat(web,react): derive the RPC endpoint from the client#212
WiktorStarczewski wants to merge 4 commits into
nextfrom
wiktor/rpc-endpoint-derive

Conversation

@WiktorStarczewski

@WiktorStarczewski WiktorStarczewski commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Fixes #188. Addresses the review feedback on #189 (supersedes its isReady-gating approach with the "derive the RPC from the client" direction @igamigo suggested).

Client PR: 0xMiden/rust-sdk#2291

Problem

On a non-testnet (e.g. devnet) configuration, page-side React code could hit the testnet default during the window before MidenProvider writes the resolved endpoint into the store: useAssetMetadata fired RPC at testnet and accountBech32 tagged addresses for testnet, even though the worker/sync correctly used devnet. The underlying issue (per the review on #189) is that the RPC config is kept in the store as a separate copy of what the client already knows.

Change

Derive the RPC endpoint from the client itself — single source of truth:

  • miden-client (companion #2291): NodeRpcClient::endpoint() (default None, overridden by GrpcClient) + Client::rpc_endpoint().
  • web-client: WebClient.endpoint() and RpcClient.endpoint(). WebClient caches the endpoint at creation (from the RPC client) so it's readable synchronously, without locking the async inner cell.
  • react-sdk: useAssetMetadata and accountBech32 read client.endpoint() instead of config.rpcUrl. client exists only after init completes, so there's no pre-config window; addresses fall back to the raw id when the network can't be confirmed.

Verification

  • ✅ Rust bindings compile-checked locally for both the browser (wasm32) and Node.js targets against the linked client branch.
  • ✅ react-sdk vitest suite green locally (786 tests) and the coverage gate passes (98.86 / 94.91 / 100 / 98.86). useAssetMetadata/accountBech32 and the shared mock updated to the client-endpoint sourcing; added a test that no RPC fires before a client exists.
  • ⛓️ Blocked on #2291 merging to miden-client next (the linked-client gate stays pending until then). CI auto-injects the client patch from the Client PR: marker above.
  • ⚠️ tsc and the Playwright accountBech32 test run in CI against the freshly-built WASM (not built locally).

Add `WebClient.endpoint()` and `RpcClient.endpoint()` (backed by miden-client's
new `NodeRpcClient::endpoint` / `Client::rpc_endpoint`), returning the node URL
the client is configured to talk to. `WebClient` caches it at creation so it can
be read synchronously without locking the async `inner` cell.

The React SDK now derives the RPC endpoint from the live client instead of a
separately-stored `config.rpcUrl` copy: `useAssetMetadata` and `accountBech32`
read `client.endpoint()`. `client` exists only once the provider has finished
initializing, so a configured (e.g. devnet) app no longer reads an unset URL and
falls back to testnet during the init window; addresses are tagged for the right
network, falling back to the raw id when the network can't be confirmed.

Supersedes the gating approach in #189 (addresses the reviewer's "derive the RPC
from the client" feedback). Requires miden-client 0xMiden/rust-sdk#2291.
@github-actions

Copy link
Copy Markdown

🔗 Linked client PR: 0xMiden/miden-client#2291

Field Value
Patched at 0xMiden/rust-sdk@wiktor/rpc-endpoint-accessor
Pin (head sha) db29e0aa1ee83f9246d0fe00e2042a8479a0d83c
Upstream state open (merged: false)

This run is testing against the linked PR's head. The published artifact will use the canonical miden-client source — CI on main/next does not auto-patch.

Local-dev parity:

scripts/dev-with-client-pr.sh 2291    # apply the same patch locally
scripts/dev-with-client-pr.sh --clear                            # remove it before commit

…point

Provide a client (with endpoint()) in the useAssetMetadata test and the shared
createMockWebClient mock so hooks that derive the RPC endpoint from the live
client fetch as expected; add a test that no RPC fires before a client exists.
@WiktorStarczewski
WiktorStarczewski marked this pull request as ready for review June 29, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant