Skip to content

Commit 0e1b455

Browse files
committed
Merge branch 'feat/free-rpc-definition'
2 parents b7f50c1 + 0052307 commit 0e1b455

File tree

15 files changed

+675
-36
lines changed

15 files changed

+675
-36
lines changed

.changeset/shiny-seas-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@konfeature/erpc-config-generator": patch
3+
---
4+
5+
Add a new `evm+free` type of upstream (alongside the `buildFreeUpstreams(...)` helper) to generate placeholder upstreams that will be filled with the 15 best free rpcs

.changeset/smart-maps-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@konfeature/erpc-config-generator": patch
3+
---
4+
5+
Add a new `free-rpc` command to get the 15 best free rpc url for a given chain

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This project is currently under active development. Features and API may change.
1212
- [x] Write YAML config file for eRPC config
1313
- [x] Helpers for networks, upstream, and auth configurations
1414
- [x] Support for various blockchain networks and RPC providers
15+
- [x] Automatic generation of free RPC upstreams using `evm+free` type
16+
- [x] Command to fetch best free RPC URLs for a given chain
1517
- [ ] More stuff within the CLI (config validity check, docker file generation, version specification etc)
1618
- [ ] Cleaner rate limit configuration and auto completion
1719
- [ ] Builder pattern with chaining (like `createProject(...).addRateLimits(...)/* a few more steps */.write(...)`)
@@ -78,6 +80,7 @@ bun erpc-config --config ./configs/my-erpc-config.ts --out ./configs/my-erpc-con
7880
# Explicitly use the generate command
7981
bun erpc-config generate --config ./custom-config.ts
8082
```
83+
Note: When using `evm+free` upstream type, the generator will automatically fetch and include the 15 best free RPC URLs for the specified chain in the output YAML.
8184

8285
### Validate Command
8386

@@ -100,6 +103,24 @@ bun erpc-config validate
100103
bun erpc-config validate --config ./configs/my-erpc-config.ts
101104
```
102105

106+
### Free RPC Command
107+
108+
Fetch the 15 best free RPC URLs for a given chain:
109+
110+
```
111+
erpc-config free-rpc --chain-id <chainId>
112+
```
113+
114+
Options:
115+
--chain-id The chain ID to fetch free RPC URLs for (required)
116+
117+
Example:
118+
119+
```bash
120+
# Fetch free RPC URLs for Ethereum mainnet (chain ID 1)
121+
bun erpc-config free-rpc --chain-id 1
122+
```
123+
103124
### General CLI Options
104125

105126
- `--help`, `-h`: Show help information
@@ -127,6 +148,7 @@ You can run these commands using `bun`, `npm`, or any other package runner of yo
127148
- `buildAlchemyUpstream({ apiKey, ...options })`: Configure Alchemy as an upstream provider.
128149
- `buildPimlicoUpstream({ apiKey, ...options })`: Configure Pimlico as an upstream provider.
129150
- `buildEvmUpstream<TRpc extends RpcSchema>({ id, endpoint, ...options })`: Configure a generic EVM upstream provider with customizable RPC schema.
151+
- `buildFreeUpstreams({ chains, ...options})`: Configure placeholder upstreams that will be filled with the 15 best free RPCs for the specified chain.
130152

131153
### Projects
132154

@@ -150,6 +172,20 @@ All other exported types (such as `Config`, `ServerConfig`, `DatabaseConfig`, et
150172

151173
For a complete list of available types, refer to the type definitions in the library.
152174

175+
## Dependencies
176+
177+
This package relies on the following main dependencies:
178+
179+
- [viem](https://viem.sh/): (Peer Dependency) A TypeScript interface for Ethereum, providing lightweight and type-safe modules for interacting with the blockchain.
180+
181+
- [@ubiquity-dao/rpc-handler](https://github.com/ubiquity/rpc-handler): (Optional Peer Dependency) Used for fetching and comparing free RPC URLs from chainlist. Only required if you intend to use the free RPC features.
182+
183+
- [erpc](https://www.erpc.cloud/): The core RPC load balancer that this config generator is designed for. It offers fault-tolerant EVM RPC load balancing with reorg-aware permanent caching and auto-discovery of node providers.
184+
185+
- [gluegun](https://github.com/infinitered/gluegun): A toolkit used for building the command-line interface of this config generator, offering a robust set of utilities for creating TypeScript-powered CLI apps.
186+
187+
Please ensure you have the required peer dependencies installed in your project when using this package. The `@ubiquity-dao/rpc-handler` is only necessary if you plan to utilize the free RPC functionality.
188+
153189
## Usage examples
154190

155191
For a simple setup, please refer to the [simple example](example/simple.ts) in the repository.

bun.lockb

19.1 KB
Binary file not shown.

example/simple.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { arbitrumSepolia, optimismSepolia, polygonAmoy } from "viem/chains";
1+
import {
2+
arbitrum,
3+
arbitrumSepolia,
4+
optimism,
5+
optimismSepolia,
6+
polygon,
7+
polygonAmoy,
8+
} from "viem/chains";
29
import {
310
buildAlchemyUpstream,
411
buildEnvioUpstream,
@@ -7,6 +14,7 @@ import {
714
buildProject,
815
envVariable,
916
} from "../src";
17+
import { buildFreeUpstreams } from "../src/upstreams";
1018

1119
/* -------------------------------------------------------------------------- */
1220
/* 1. Create everything you will need in your config */
@@ -56,6 +64,13 @@ export default buildErpcConfig({
5664
networks,
5765
upstreams: [alchemyUpstream, envioUpstream],
5866
}),
67+
buildProject({
68+
id: "free-erpc",
69+
networks,
70+
upstreams: buildFreeUpstreams({
71+
chains: [polygon, polygonAmoy, arbitrum, optimism],
72+
}),
73+
}),
5974
],
6075
},
6176
});

0 commit comments

Comments
 (0)