Registry / blockchain / ethjs-format

ethjs-format

JSON →
library0.2.7jsnpmunverified

An Ethereum RPC payload formatter that converts between JavaScript values and hex-encoded RPC data. Version 0.2.7 (stable) with irregular releases. Provides bidirectional formatting for all standard Ethereum RPC methods, handling BigNumber, hex, and address conversions. Unlike ethers or web3, it is focused solely on RPC formatting without network transport.

npm install ethjs-format
INSTALL
IMPORT
SIG · ETHJS-FORMAT
E
ethjs-format
blockchainjavascriptv0.2.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatInputs
import { formatInputs } from 'ethjs-format'
const formatInputs = require('ethjs-format').formatInputs
ESM named export. Also available via CJS require, but named import is preferred.
formatOutputs
import { formatOutputs } from 'ethjs-format'
const formatOutputs = require('ethjs-format').formatOutputs
ESM named export.
format
import * as format from 'ethjs-format'
const format = require('ethjs-format')
Import as namespace to access both formatInputs and formatOutputs.

Shows how to format RPC inputs and outputs using ethjs-format for the eth_getBalance method.

import { formatInputs, formatOutputs } from 'ethjs-format'; // Format an eth_getBalance input const inputPayload = formatInputs('eth_getBalance', [ "0x407d73d8a49eeb85d32cf465507dd71d507100c1", 405938494 ]); console.log(inputPayload); // Output: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x1832213E'] // Format an eth_getBalance output (hex balance) const outputPayload = formatOutputs('eth_getBalance', "0x0234c8a3397aab58"); console.log(outputPayload.toString(10)); // Output: 158972490234375000
Debug
Known issues
gotchaformatInputs and formatOutputs expect the method name exactly as in the RPC spec, including case sensitivity.
fix
Use exact method names like 'eth_getBalance', not 'eth_getbalance'.
affects: >=0.1.0
gotchaOutput format returns a BigNumber (bn.js) for numeric results, not a plain number or string.
fix
Use .toString(10) or .toNumber() to convert.
affects: >=0.2.0
deprecatedThe package is no longer actively maintained; consider using ethers or web3 for full Ethereum interaction.
fix
Migrate to ethers.js or web3.js which include built-in formatting.
affects: >=0.2.0
Errors
Common errors & fixes
Error: Method 'eth_getbalance' not recognized
Method name is case-sensitive and must match the exact RPC method name.
fix
Use 'eth_getBalance' (capital B) instead.
TypeError: formatOutputs(...).toString is not a function
Output may be a string (hex) not a BigNumber; the returned type depends on the RPC method.
fix
Check the return type: for methods returning numbers, use .toString(10); for hex strings, use it directly.
Error: Cannot find module 'ethjs-util'
ethjs-format depends on ethjs-util, which may not be installed.
fix
Run 'npm install ethjs-format' which includes dependencies, or install manually 'npm install ethjs-util'.
Upgrade
Version history
0.2.7latest on npm
Audit
Dependencies
ethjs-utilrequiredHex, address, and big number utilities
bn.jsrequiredBig number arithmetic
Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
1
Resources
ethjs-format — npm install ethjs-format · libregistry