Skip to content

feat(rpc): expose the configured node endpoint URL#2291

Open
WiktorStarczewski wants to merge 2 commits into
nextfrom
wiktor/rpc-endpoint-accessor
Open

feat(rpc): expose the configured node endpoint URL#2291
WiktorStarczewski wants to merge 2 commits into
nextfrom
wiktor/rpc-endpoint-accessor

Conversation

@WiktorStarczewski

Copy link
Copy Markdown
Contributor

What

Adds NodeRpcClient::endpoint(&self) -> Option<&str> (default None, overridden by GrpcClient to return its configured URL) and Client::rpc_endpoint(&self) -> Option<&str>.

Why

Lets consumers read the endpoint a client is configured to talk to without a network round-trip or threading the URL alongside the client. The trait method has a default (None), so it's non-breaking for external NodeRpcClient implementors; mocks inherit it.

Motivating consumer: web-sdk's React layer derives the RPC endpoint from the WebClient itself (single source of truth) instead of a separately-stored copy in its store — see the linked web-sdk PR.

Add `NodeRpcClient::endpoint` (default `None`, overridden by `GrpcClient` to
return its configured URL) and `Client::rpc_endpoint`, so consumers can read
the endpoint a client is talking to without a network round-trip or threading
the URL alongside the client.

Motivating consumer: the web-sdk needs the React layer to derive the RPC
endpoint from the WebClient itself rather than a separately-stored copy.
WiktorStarczewski added a commit to 0xMiden/web-sdk that referenced this pull request Jun 29, 2026
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.

@igamigo igamigo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I expanded a bit on my original comment on 0xMiden/web-sdk#189 (comment). In short, I think we could resolve the original problem without modifying the RPC trait. I left a couple of comments in case we want to merge this anyway.

///
/// Defaults to `None` for implementations that don't track an endpoint (e.g. test mocks); real
/// transports return their configured URL.
fn endpoint(&self) -> Option<&str> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go this route, I think we should make this return a more strict type than &str, to ensure validity by construction. For example, it could be Endpoint.

Comment on lines +140 to +141
/// Defaults to `None` for implementations that don't track an endpoint (e.g. test mocks); real
/// transports return their configured URL.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could avoid returning Option<> (mock implementations can provide mocked endpoints). Also I think I would avoid mentioning mock implementations specifically on the docs.

@SantiagoPittella SantiagoPittella left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the deeply coupled motive of this change to the React web-client, should this be a method of the web client itself? Just a getter of the inner value stored in the object

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.

3 participants