Xalava / Anix

Minimal and flexible JSON-RPC wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Anix

NPM Package

Image description

Minimal (< 1 Kb), dependency-free and flexible JSON-RPC client library for Ethereum.

The goal is to make it easy to work with RPC endpoints.

This library uses JavaScript Proxy object to allow arbitrary prototype method calls, the API offers an intuitive translation to the raw RPC methods, where eth_getLogs becomes eth.getLogs(), and so on.

Installation

$ npm i --save-dev anix-js

Basic usage:

main.mjs:

import {Anix} from 'anix-js'

const eth = new Anix('eth', <YOUR HTTP RPC ENDPOINT>)

console.dir(await eth.getBlockByNumber('latest', false))
$ node main.mjs

- or - 

$ bun run main.mjs

Can be used for arbitrary/custom RPC methods:

import {Anix} from 'anix-js'

const eth = new Anix('eth', <YOUR HTTP RPC ENDPOINT>)

await eth.sendBundle({})

Read-Eval-Print-Loop

Anix has a built-in REPL script, making it easy to prototype.

$ npx anix-js http://my-rpc-url.xyz

   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦
 ♦   ♦   ♦   ♦  Welcome to Anix  ♦   ♦   ♦   ♦
   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦   ♦

Anix > await eth.blockNumber()
'0x12705de'

Benefits of using Anix:

  • Works with any set of custom RPC methods, because of its native proxy object.
  • It resembles the Geth console JavaScript APIs.
  • It's incredibly portable, with a minimal footprint (less than 1kb minified).
  • It uses the native fetch method, implemented on top of Undici.
  • No dependencies attached: Anix is not prone to supply-chain attacks.

Check the examples directory for boilerplate code.

Questions?

Ping me on twitter.

About

Minimal and flexible JSON-RPC wrapper

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%