https://github.com/ethersphere/etherproxy
Etherproxy is a JSON-RPC reverse proxy tool designed for caching requests.
https://github.com/ethersphere/etherproxy
ethereum
Last synced: about 1 year ago
JSON representation
Etherproxy is a JSON-RPC reverse proxy tool designed for caching requests.
- Host: GitHub
- URL: https://github.com/ethersphere/etherproxy
- Owner: ethersphere
- Created: 2023-04-04T12:51:14.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-07-29T08:30:59.000Z (almost 2 years ago)
- Last Synced: 2024-12-22T20:02:07.408Z (over 1 year ago)
- Topics: ethereum
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Etherproxy
Etherproxy is a robust and lightweight JSON-RPC reverse proxy tool designed for **optimising requests** and **providing failover support**.
## Usage
```
npx etherproxy --port 9000 --target https://gno.getblock.io/YOUR_TOKEN/mainnet/ --expiry 2000
```
The command above starts the JSON-RPC reverse proxy...
- on port 9000 (`--port`)
- forwarding all requests to GetBlock using your token and mainnet (`--target`)
- grouping requests together within 2 seconds (`--expiry`)
Make sure to replace `YOUR_TOKEN` with your actual token.
Supply multiple JSON-RPC `--target` with a comma-separated string:
```
npx etherproxy --target https://gno.getblock.io/YOUR_TOKEN/mainnet/,https://rpc.gnosischain.com
```
## Verify the tool is running
Execute the `curl` command shown below repeatedly and inspect the logs of Etherproxy.
```sh
curl http://localhost:9000 -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
```
When the text `Cache hit` appears, it indicates that a request was saved and immediately returned:
```txt
Key: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}
Cache hit: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}
Cache hit: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}
Cache hit: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}
```
## Benefits
### Caching
Etherproxy provides several benefits in multi-node scenarios. For instance, requests such as `eth_blockNumber` and `eth_getLogs` are frequently called, sometimes generating many unnecessary requests. By using a reverse proxy, the same requests made within a small time period are grouped together and sent to your JSON-RPC endpoint only once.
As a result, all local nodes receive identical correct responses, and the number of actual requests sent is significantly reduced, which helps to **preserve your request quota** in case of a paid third-party, or **reduce the load** when you run your own Ethereum node.
### Failover
Failover is an essential aspect of maintaining high availability and reliability in network services. Etherproxy's seamless failover capability ensures that if one JSON-RPC endpoint becomes unreachable, the traffic is automatically redirected to another configured endpoint without interruption.
## Error handling
Whenever an error is thrown, Etherproxy responds with a `503 Service Unavailable` status.