Skip to content

JSON-RPC Request Batching#39

Open
jiexi wants to merge 7 commits into
mainfrom
json-rpc-request-batching
Open

JSON-RPC Request Batching#39
jiexi wants to merge 7 commits into
mainfrom
json-rpc-request-batching

Conversation

@jiexi
Copy link
Copy Markdown
Member

@jiexi jiexi commented Mar 27, 2024

Summary

This proposal aims to extend the MetaMask JSON-RPC API that is accessible via window.ethereum.request() to include support for batching requests. Batched requests would be processed in parallel by the wallet. All passthrough requests in a batch will be sent to the RPC endpoint in a batch. All requests requiring user confirmation will have results returned after user approval/rejection. Results will be returned as available and are not guaranteed to be in the same order as the respective requests. Introducing native support for request batching allows developers to improve Dapp efficiency and aligns the MetaMask JSON-RPC API closer to the JSON-RPC 2.0 specification.

Comment thread MIPs/mip-x.md Outdated
@vandan
Copy link
Copy Markdown
Contributor

vandan commented Mar 28, 2024

We should confirm whether the purpose of batch JSON-RPC requests is primarily for performance or as a way for dapps to give a hint to MetaMask about how they would prefer MetaMask to group certain calls (potentially influencing wallet UX).

If it's the latter, then we may want to consider adjusting the examples and descriptions in the developer adoption and user experience considerations sections. For instance, batch wallet_watchAsset calls might provide a more relevant example.

Comment thread MIPs/mip-x.md Outdated
@andreahaku
Copy link
Copy Markdown

@jiexi RPC Batching is already supported via MetaMask SDK and it supports both MM Extension and MM Mobile.
You can find more information here

@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Apr 8, 2024

@andreahaku Right, I am aware that MetaMask SDK has implemented a form of RPC batching already. I believe this should be supported at the Wallet layer itself. Currently any implementations of batching outside of the Wallet can only make several single requests in quick succession. This will not result in an actual batched RPC request being sent to the underlying RPC endpoint, but several separate requests instead. Adding RPC batching support directly in the Wallet itself would help us to realize the full benefits of RPC batching

Comment thread MIPs/mip-x.md
// Request
await window.ethereum.request([
{
"id": 1,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

currently the id gets generated on metamasks side, for batching we should probably honor their id

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It seems that the generated id gets mapped back to any user passed one

https://github.com/MetaMask/core/blob/main/packages/json-rpc-engine/src/idRemapMiddleware.ts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

to clarify, i think we need to make changes to the provider/middleware to not add an id to a request object in the case of batches

@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Apr 19, 2024

We should confirm whether the purpose of batch JSON-RPC requests is primarily for performance or as a way for dapps to give a hint to MetaMask about how they would prefer MetaMask to group certain calls (potentially influencing wallet UX).

If it's the latter, then we may want to consider adjusting the examples and descriptions in the developer adoption and user experience considerations sections. For instance, batch wallet_watchAsset calls might provide a more relevant example.

This is for performance reasons, as one of the biggest draws I see is that it enables passthrough messages to be grouped and sent as a single batch call to the underlying rpc endpoint itself which something that currently isn't possible

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.

4 participants