Ethjs is a lightweight, highly optimized JavaScript utility library designed for interacting with the Ethereum blockchain. Released in its current stable version 0.4.0 in 2018, it aimed to provide a more modular and async-only alternative to the then-dominant `web3.js` library, featuring `BN.js` for large number arithmetic and a focus on smaller bundle sizes. However, the project has been unmaintained since its last publish nearly eight years ago. Developers should be aware that `ethjs` is effectively abandoned; its GitHub repository explicitly recommends using `ethers.js` instead. Modern Ethereum development typically leverages actively maintained libraries like `ethers.js` or the `@ethereumjs` monorepo, which offer contemporary features such as ESM support, TypeScript definitions, and native JavaScript `BigInt` for handling large numbers, providing a more robust and future-proof development experience.
npm install ethjsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates initializing Ethjs with an HTTP provider, fetching blockchain data using a callback, converting units with a static utility, and interacting with a basic ERC-20 contract using a promise-based API.
Migrate your project to a modern, actively maintained Ethereum library such as `ethers.js` (e.g., `npm install ethers`) or specific `@ethereumjs` packages (e.g., `npm install @ethereumjs/tx`).
If continuing to use `ethjs`, explicitly manage conversions between `BN.js` objects and other number types. For new projects, switch to libraries that support `BigInt` natively to avoid this impedance mismatch.
Ensure your project uses `require('ethjs')` for importing. If you need ESM compatibility, you must use a transpiler like Babel or switch to a modern Ethereum library that offers hybrid CJS/ESM builds.Standardize your async patterns. For callback-based functions, consider wrapping them in Promises (e.g., using `util.promisify`) to maintain a consistent promise-based workflow throughout your application.
Change your import statement to `const Eth = require('ethjs');`. Ensure `ethjs` is listed in your `package.json` dependencies and installed (`npm install ethjs`).Ensure `Eth` is imported as the main module (`const Eth = require('ethjs');`) and static methods like `toWei` are called directly on `Eth` (e.g., `Eth.toWei(value, unit)`). Do not attempt `const { toWei } = require('ethjs');`.