A simple cache for Ethereum RPC requests that wraps provider.send() with caching strategies. Version 2.1.0 is the latest stable release, with no breaking changes in the 2.x line. It supports extensible caching strategies (default: per-block and permanent), optional custom cache store, and strict mode to allow or disallow unknown RPC methods. Ships TypeScript types. Requires Node >=18.
npm install eth-rpc-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a cached JSON-RPC provider using ethers.js, caching eth_chainId permanently and eth_blockNumber per block.
Add Object.setPrototypeOf(cachedProvider, Object.getPrototypeOf(provider)) after spreading the provider object.
Replace `import ethRpcCache from 'eth-rpc-cache'` with `import { createEthRpcCache } from 'eth-rpc-cache'`.Provide a custom strategy array that does not include permanentStrategy, or delete cache entries manually.
Set allowOthers: false to block unknown methods if needed.
After spreading, call Object.setPrototypeOf(cachedProvider, Object.getPrototypeOf(provider)).
Run `npm install eth-rpc-cache` and use correct import: `import { createEthRpcCache } from 'eth-rpc-cache'`.Set `allowOthers: true` in options, or add a strategy for that method.