Save JSON-RPC
sjrpc or Save JSON-RPC is a Reverse Proxy focused on to reduce remote Ethereum/Web3 JSON-RPC calls to thrid-party nodes.
How it works
Using an embedded and local BadgerDB database, sjrpc hashes the Request,
uses the request hash as Key, perform the remote JSON-RPC call and saves the remote response locally. At next call it gets the content from the local database.
Installation
Download
Installation from sources
Install Go Language
Visit Golang Download and Install page and follow the instructions.
Clone this repository
Compile it
In case you use Mac or Linux, install make
if you don't have it already, then run:
make build
In case you use Windows, run:
go build -o bin/sjrpc.exe cmd/main.go
Usage
Set your RPC Server URL using environment variables
Set SJRPC_URL
with your remote RPC Server URL
Example:
export SJRPC_URL=https://mainnet.infura.io/v3/<YOUR INFURA API KEY>
Run it
In case you use Mac or Linux run:
make run
In case you use Windows, run:
bin/sjrpc.exe
It will start a localhost Web Server on port 8434. This port number is fixed to avoid the risk you mess it with standard dev ETH node port: 8545
Call it
Configure your Foundry, Truffle, Go, Hardhat or any Web3 application to use this RPC server: http://localhost:8434
.
Clean Up
When you need to call another Blockchain network your cache gets outdate and you need to clean it up. To do so you need to call the cleanup
endpoint:
http://localhost:8434/cleanup
Perfomance hint
It runs better in 64-bit architect processors, such M1/M2 Apple chips, or Intel i7. The reason is it uses Blake2b 512 bits.
TODOs
- Add chainID as parameter to support different blockchains networks simultaneously.
- To optimize the response removing ID from hash generation, so same requests from different clients can use the same cache,
but update it back to the original ID of the call to allow SJRPC to be compatible with Ethers.