|
1 | 1 | # Etherproxy |
2 | 2 |
|
3 | | -## Usage |
| 3 | +Etherproxy is a JSON-RPC reverse proxy tool designed for caching requests. |
4 | 4 |
|
5 | | -To launch a JSON-RPC reverse proxy on port 9000 and forward all requests to GetBlock using your token and mainnet, run: |
| 5 | +## Usage |
6 | 6 |
|
7 | 7 | ``` |
8 | | -npx etherproxy 9000 https://gno.getblock.io/YOUR_TOKEN/mainnet/ |
| 8 | +npx etherproxy --port 9000 --target https://gno.getblock.io/YOUR_TOKEN/mainnet/ --expiry 2000 |
9 | 9 | ``` |
10 | 10 |
|
| 11 | +The command above starts the JSON-RPC reverse proxy... |
| 12 | + |
| 13 | +- on port 9000 (`--port`) |
| 14 | +- forwarding all requests to GetBlock using your token and mainnet (`--target`) |
| 15 | +- grouping requests together within 2 seconds (`--expiry`) |
| 16 | + |
11 | 17 | Make sure to replace `YOUR_TOKEN` with your actual token. |
12 | 18 |
|
| 19 | +## Verify the tool is running |
| 20 | + |
| 21 | +Execute the `curl` command shown below repeatedly and inspect the logs of Etherproxy. |
| 22 | + |
| 23 | +```sh |
| 24 | +curl http://localhost:9000 -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' |
| 25 | +``` |
| 26 | + |
| 27 | +When the text `Cache hit` appears, it indicates that a request was saved and immediately returned: |
| 28 | + |
| 29 | +```txt |
| 30 | +[~] Key: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[]} |
| 31 | +[~] Cache hit: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[]} |
| 32 | +[~] Cache hit: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[]} |
| 33 | +[~] Cache hit: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[]} |
| 34 | +``` |
| 35 | + |
13 | 36 | ## Benefits |
14 | 37 |
|
15 | | -The JSON-RPC reverse proxy provides several benefits, particularly in multi-node scenarios. For instance, requests such as `eth_blockNumber` and `eth_getLogs` are frequently called, and in such scenarios, it's easy to quickly exhaust your request quota. |
| 38 | +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. |
| 39 | + |
| 40 | +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. |
| 41 | + |
| 42 | +## Error handling |
16 | 43 |
|
17 | | -However, by using the reverse proxy, the same requests made within 2 seconds are grouped together and sent to your third-party service only once. As a result, all local nodes receive the same response, which can significantly reduce the number of requests made and help preserve your quota. |
| 44 | +Whenever an error is thrown, Etherproxy responds with a `503 Service Unavailable` status. |
0 commit comments