JSON-RPC Request Batching#39
Conversation
|
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 |
|
@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 |
| // Request | ||
| await window.ethereum.request([ | ||
| { | ||
| "id": 1, |
There was a problem hiding this comment.
currently the id gets generated on metamasks side, for batching we should probably honor their id
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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 |
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.