An open API service indexing awesome lists of open source software.

https://github.com/dodoex/web3-rpc-proxy

A cluster-deployable proxy middleware for accessing EVM blockchains, designed to provide users with the highest quality 🌟, most stable πŸ’ͺ, and up-to-date block height πŸ“ˆ proxy access. πŸš€βœ¨βœ¨βœ¨
https://github.com/dodoex/web3-rpc-proxy

Last synced: 2 months ago
JSON representation

A cluster-deployable proxy middleware for accessing EVM blockchains, designed to provide users with the highest quality 🌟, most stable πŸ’ͺ, and up-to-date block height πŸ“ˆ proxy access. πŸš€βœ¨βœ¨βœ¨

Awesome Lists containing this project

README

        

Β 

logo


Web3 RPC Proxy



Go Version Badge
Β 
Codacy Badge
Β 
License Badge
Β 
Release Badge


web3-rpc-proxy - A cluster-deployable EVM blockchains rpc proxy middleware | Product Hunt


δΈ­ζ–‡
Β |Β 
English


## :dart: Introduction

Web3 RPC Proxy is a proxy middleware for accessing EVM blockchains that supports cluster deployment, designed to provide users with optimal, stable, and latest block height proxy access.


## :sparkles: Features

- :zap: High concurrency, fast access
- :raised_hands: Combined with [web3-rpc-provider](https://github.com/DODOEX/web3-rpc-provider) to automatically load available free endpoints
- :dizzy: Flexible support for multiple chains
- :mag: Efficient endpoint selection
- :construction_worker: Supports distributed deployment
- :chart_with_upwards_trend: Comprehensive reporting support


### Functionality

- Tenant isolation
- Multi-bucket rate limiting
- Request result caching and reuse
- WSS endpoint configuration
- Dynamic endpoint configuration updates
- JSON-RPC API schema validation
- Alternating retries across multiple endpoints
- Prometheus metrics
- Grafana monitoring reports


## :rocket: Deployment

```bash
# Build the docker image
$ docker build ./Dockerfile -t dodozoo/web3-rpc-proxy:latest

# Run the image
$ docker run -p 8080:8080 -d dodozoo/web3-rpc-proxy:latest
```

Or

```bash
# Start the service using docker compose
$ docker-compose up
```

Modify system configuration using the following environment variables:

- `WEB3RPCPROXY_APP_HOST` to set the service host and port, default is `0.0.0.0:8080`
- `WEB3RPCPROXY_ETCD_CONFIG_ENDPOINTS` to set the ETCD endpoints
- `WEB3RPCPROXY_ETCD_SETUP_CONFIG_FILE` to specify the system startup configuration path on ETCD
- `WEB3RPCPROXY_ETCD_ENDPOINTS_CONFIG_FILE` to specify the endpoint configuration path on ETCD for each chain

### Dependencies

- PostgreSQL Depends on [the Tenant table](internal/database/schema/tenant.go)
- Redis Used for distributed rate limiting of Tenant in the service
- Amqp, optional After completion, the request information will be published to the mq

### Grafana Reports
Import [the Grafana template file](config/grafana.json)

![Grafana1](docs/grafana1.jpg)
![Grafana2](docs/grafana2.jpg)
![Grafana3](docs/grafana3.png)


## :bulb: Usage
The usage is straightforward, just make a JSON-RPC request to a specific chain.

```bash
$ curl --location --request POST 'https://localhost:8080/{{CHAIN}}' \
--header 'Content-Type: application/json' \
--data-raw '[
{
"jsonrpc": "2.0",
"id": 1,
"method": "net_version",
"params": []
},
{
"jsonrpc": "2.0",
"id": 2,
"method": "eth_blockNumber",
"params": []
}
]'
```

- `CHAIN`: Required Represents
the Chain ID or code of a specific blockchain, refer to the YAML configuration file below.
### Request Parameters:
- `x_api_key`: Required
The client must provide an API key when accessing the service, otherwise, it will be rejected with a 403 error. It can also be provided via the `X-API-KEY` header.
- `x_api_bucket`: Optional
Allows the client to specify different buckets based on the situation, placing different values into different buckets for separate rate limiting. It can also be provided via the `X-API-BUCKET` header, such as using different chain IDs as bucket values to isolate rate limiting.
- `cache`: Optional, default `true`
Whether to use cache, acceptable values are `true`, `false`
- `timeout`: Optional, default `30000ms`
Timeout duration, if exceeded, the request returns a 408 error
- `attempts`: Optional, default `3`
Maximum retry attempts, 0 means no retries
- `attempt_strategy`: Optional, default `same`
The strategy for selecting endpoints during failure retries: `same` always retries the same endpoint, `rotation` alternates retries among available endpoints
- `endpoint_type`: Optional, string, `default`
Specifies the type of endpoint to select: `default` automatically selects the most suitable endpoint type based on the request method, acceptable values are `fullnode`, `activenode`

For details on the JSON-RPC call body, see [JSON-RPC API METHODS](https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods)


## :wrench: Configuration
See [the default configuration file](config/default.yaml)


## :technologist: Development

### Starting the Project
```bash
# Clone the project
$ git clone https://github.com/DODOEX/web3-rpc-proxy

# Navigate to the project directory
$ cd web3-rpc-proxy

# Install project dependencies
go mod download

# Start the project
go run ./cmd/main.go
```

### Local Debugging
Add a configuration `config/local.yaml` in the directory to override `config/default.yaml` for local development and debugging.

> [!NOTE]
> The endpoint configuration for each chain should be written under the `endpoints` configuration item.
> See [the default configuration file](config/default.yaml)

### Technology
The project uses the following technologies:

- [Fasthttp](https://github.com/valyala/fasthttp)
- [PostgreSQL](https://www.postgresql.org)


### Architecture

![architecture](docs/architecture.png)

## :speech_balloon: FAQs

- How to select an endpoint?
> The endpoints are selected based on the nodes configured in WEB3RPCPROXY_ETCD_ENDPOINTS_CONFIG_FILE, and are chosen by sorting them according to their calculated scores.

- What is the configuration priority?
> The configuration priority is: local < env < etcd.


## :busts_in_silhouette: Contribute
If you want to contribute to the Web3 RPC Proxy project:

Fix issues: Find and fix issues in the project.
Write documentation: Improve and write relevant documentation for the project.
Write tests: Write and optimize test cases for the project.

If you want to show appreciation or support the continued development of the Web3 RPC Proxy project, you can do so by:

Giving the project a GitHub Star. Supporting the project by donating a cup of tea.


## :memo: License
This project is under license from MIT. For more details, see [the LICENSE file](LICENSE).

Β 

Back to top