Match Ethereum batch RPC replies to the correct requests

A batch reduces round trips, but response ordering can change. A balance can end up under the wrong label if a client zips replies to requests by array position.

Use distinct request IDs

Send the batch below to an Ethereum HTTP endpoint that accepts batches. Construct a map from each ID to its method before sending the array.

[{"jsonrpc":"2.0","id":"chain","method":"eth_chainId","params":[]},{"jsonrpc":"2.0","id":"height","method":"eth_blockNumber","params":[]}]

If the height reply arrives first, decode it as a block number. Handle errors for each ID independently, and reject duplicate or missing replies for requests expecting a response. A failed item does not erase the successful result of its neighbor.

Keep dependent reads in separate stages

Batching does not create a transaction or an atomic snapshot. If one call needs a block hash returned by another, fetch the hash first and then construct the dependent batch using that fixed block wherever the methods allow it. jsonrpc.org JSON-RPC 2.0