Dynamically fetches, caches, and crawls RPC endpoints on all (or specified) chains, and acts as a round-robin load balancer using the generated list to provide a single reliable interface for general work or research involving multiple chains.
Inspired by the work of Jacob Gadikian and Eco-stake, this tool combines Notional's RPC crawler logic, and the cosmos.directory Load balanced proxy endpoint created by "Tom". It is intended as a personal load balancer / unified endpoint for multiple Cosmos-SDK / IBC chain API endpoints.
- Node.js (v14 or later)
- Yarn package manager
-
Clone the repository:
git clone https://github.com/Cordtus/lazy-loadbalancer.git cd lazy-loadbalancer
-
Install dependencies:
yarn install
-
Create a
.env
file with your GitHub personal access token:echo "GITHUB_PAT=your_github_personal_access_token" > .env
-
Build the project:
yarn build
-
Start the Node.js server:
yarn start
-
Update data for all chains from the registry:
curl -X POST http://localhost:3000/api/update-all-chains
-
Update data for a specific chain:
curl -X POST http://localhost:3000/api/update-chain/osmosis
-
Crawl all chains to discover new RPC endpoints:
curl -X POST http://localhost:3000/api/crawl-all-chains
-
Crawl a specific chain:
curl -X POST http://localhost:3000/api/crawl-chain/osmosis
-
Get a list of all chains:
curl http://localhost:3000/api/chain-list
-
Get a summary of all chains (name and number of endpoints):
curl http://localhost:3000/api/chains-summary
-
Get endpoints for a specific chain:
curl http://localhost:3000/api/rpc-list/osmosis
To send a load-balanced RPC request to any chain, use the following format:
curl -X [METHOD] http://localhost:3000/lb/[CHAIN]/[ENDPOINT]
For example, to get the status of the Osmosis chain:
curl http://localhost:3000/lb/osmosis/status
The load balancer will automatically select an available RPC endpoint for the specified chain and proxy the request.
Logs are stored in the ./logs
directory, with separate files for each module (balancer, crawler, api).
src/
: Source codebalancer.ts
: Main load balancing logiccrawler.ts
: Network crawling and endpoint discoveryapi.ts
: Custom API endpoints for chain managementfetchChains.ts
: Functions for fetching chain data from the registryutils.ts
: Utility functionstypes.ts
: TypeScript type definitionslogger.ts
: Logging configuration
data/
: JSON files for chain data and IP listslogs/
: Log files
Contributions are welcome. Issues and pull requests are much appreciated.
This project is licensed under the MIT License.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.