Skip to content

Latest commit

 

History

History
90 lines (60 loc) · 2.66 KB

README.md

File metadata and controls

90 lines (60 loc) · 2.66 KB

hero banner with nexus dog

npm version npm downloads Documentation Maintenance license: MIT

Discord GitHub Actions Status

Introduction

Welcome to Nexus - a simple TypeScript proxy server for any Ethereum JSON RPC compliant blockchain. Instead of connecting your dApps to a blockchain node, you can connect them to Nexus and Nexus serves the requests for you. Nexus is open source and free to use.

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 alchemyNodeProvider = new NodeProvider({
  name: "alchemy",
  chain: CHAIN.ETHEREUM_MAINNET,
  url: process.env.ALCHEMY_URL,
});

const infuraNodeProvider = new NodeProvider({
  name: "infura",
  chain: CHAIN.ETHEREUM_MAINNET,
  url: process.env.INFURA_URL,
});

const nexus = Nexus.create({
  nodeProviders: [alchemyNodeProvider, infuraNodeProvider],
  port: 4005,
});

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:4005/1 \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'