A lightweight middleware that accepts Ethereum JSON-RPC requests and forwards each to a randomly chosen provider from a pool.
Note 1: This project is for research and not production-ready. Use at your own risk.
Note 2: This is meant to be run inside a trusted execution environment (TEE) so that the TEE handles all the interactions with the RPC providers instead of the dAPP or user wallet.
-
Install dependencies:
pip install -r requirements.txt
-
Configure providers: Copy
rpc-providers/example.csvtorpc-providers/rpcs.csvand update it with your RPC endpoints and API keys. -
Run the server:
uvicorn src.main:app --reload
With the server running, you can:
- Send JSON-RPC requests:
- POST to
http://localhost:8000/rpc
- View metrics:
- GET
http://localhost:8000/metrics
For example:
curl -X POST http://localhost:8000/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'returns
{"jsonrpc":"2.0","id":1,"result":"0x15eb54a"}Go to http://127.0.0.1:8000/metrics to see how many times each RPC has been
used!
You can also build it and run with Docker:
docker build -t rpc-middleware .
docker run -p 8000:8000 rpc-middleware
