Ethjs HTTP Provider

0.1.6 · abandoned · verified Wed Apr 22

ethjs-provider-http is a minimalist HTTP provider module for interacting with the Ethereum RPC layer, designed to adhere to the `web3` provider specification. It uses the `xhr2` module for its underlying HTTP requests. Released in 2016 and last updated to version 0.1.6 in January 2017, this package is part of the broader `ethjs` ecosystem, which aimed to provide a lightweight alternative to `web3.js` at the time. However, the `ethjs` suite is no longer actively maintained and has largely been superseded by modern Ethereum client libraries such as Ethers.js and the latest versions of Web3.js. There is no ongoing release cadence, and it is primarily of historical interest or for maintaining legacy applications that specifically depend on it. Its key differentiator was its simplicity and a modular approach within the `ethjs` family, but this is now overshadowed by its lack of maintenance and modern feature support.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to instantiate an `HttpProvider` and use it with `ethjs-query` to fetch block information from an Ethereum RPC endpoint. It highlights the CommonJS `require` syntax used by the library.

const HttpProvider = require('ethjs-provider-http');
const Eth = require('ethjs-query');

// NOTE: Ropsten is deprecated. Use a current testnet like Sepolia or Goerli,
// or a mainnet RPC endpoint from a service like Infura or Alchemy.
const provider = new HttpProvider('https://mainnet.infura.io/v3/' + (process.env.INFURA_API_KEY ?? ''));
const eth = new Eth(provider);

eth.getBlockByNumber(45039930, true, (err, result) => {
  if (err) {
    console.error('Error fetching block:', err);
    return;
  }
  if (result) {
    console.log('Block data:', result);
  } else {
    console.log('Block not found or null result.');
  }
});

view raw JSON →