Skill — Copyable reference implementation. Use as-is or customize. See Skills Philosophy.
Batched Provider
The batched provider accumulates multiple JSON-RPC requests and sends them as a single HTTP request, reducing network round-trips and improving performance.What is JSON-RPC Batching?
JSON-RPC 2.0 supports batching multiple requests in a single HTTP call:Quick Start
Configuration
Options
| Option | Default | Description |
|---|---|---|
wait | 10 | Milliseconds to wait before sending batch. Requests within this window are batched together. |
maxBatchSize | 100 | Maximum requests per batch. Triggers immediate send when reached. |
timeout | 30000 | HTTP request timeout in milliseconds. |
Wrapping Existing Providers
Wrap any EIP-1193 provider (MetaMask, WalletConnect, etc.):Wrapping non-HTTP providers doesn’t provide true batching. Requests are executed in parallel but still make separate calls. Use HTTP transport for true batching.
Performance Benefits
Without Batching
With Batching
- Without batching: ~500ms
- With batching: ~50ms (10x faster)
When to Use Batching vs Multicall
| Use Case | Batching | Multicall |
|---|---|---|
| Multiple RPC methods | Yes | No |
| Same contract, multiple calls | Yes | Yes |
| Atomic reads | No | Yes |
| Gas efficiency | N/A | Better |
| No contract deployment | Yes | No |
Error Handling
Per-Request Errors
Individual requests can fail independently:Batch-Level Errors
Network failures reject all pending requests:Error Types
Advanced Usage
Force Flush
Send pending requests immediately without waiting for debounce:Check Pending Count
Cleanup
Implementation Details
Request Flow
request()adds request to queue, returns Promise- Timer starts (or resets) for debounce window
- After
waitms (ormaxBatchSizereached), batch is sent - Responses are routed back to callers by
id - Individual Promises resolve/reject based on response
Response Routing
Responses are matched byid field, not array position. This handles out-of-order responses correctly:

