/nexus

A load balancing blockchain RPC reverse proxy written in TypeScript.

Primary LanguageTypeScript

hero banner with nexus dog

npm version npm downloads Documentation Maintenance license: MIT

Discord GitHub Actions Status Docker Image Size (tag)

Introduction

Welcome to Nexus - a load balancing blockchain RPC reverse proxy written in TypeScript.

Documentation

Check out our documentation for detailed instructions.

Installation

# npm
npm install @whatsgood/nexus

# pnpm
pnpm install @whatsgood/nexus

# yarn
yarn add @whatsgood/nexus

Quickstart

// node.js standalone server example

import { Nexus, NodeProvider, CHAIN } from "@whatsgood/nexus";
import { createServer } from "node:http";

const llamaRpcNodeProvider = new NodeProvider({
  name: "llama-rpc",
  chain: CHAIN.ETHEREUM_MAINNET,
  url: "https://eth.llamarpc.com",
});

const tenderlyNodeProvider = new NodeProvider({
  name: "tenderly",
  chain: CHAIN.ETHEREUM_MAINNET,
  url: "https://gateway.tenderly.co/public/mainnet",
});

const nexus = Nexus.create({
  nodeProviders: [llamaRpcNodeProvider, tenderlyNodeProvider],
  port: 4000,
});

createServer(nexus).listen(nexus.port, () => {
  console.log(`🚀 Server ready at http://localhost:${nexus.port}`);
});

Interaction

In this example, since we have configured the server to connect to Ethereum Mainnet, we supply the chain id = 1 as the endpoint.

curl \
    -X POST http://localhost:4000/1 \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'