Install Nexus

npm install @whatsgood/nexus

Configure Nexus

// 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}`);
});

Send your first request

First, start the server: npm run dev. And then, open a new terminal window and send a request to the server. You should see a response like: { "jsonrpc": "2.0", "id": 1, "result": "0x11e3b03" }.

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