Core helper utilities providing standardized error handling and data formatting for the Web3.js ecosystem
npx @tessl/cli install tessl/npm-web3-core-helpers@1.10.0Web3 Core Helpers is an internal utility package that provides standardized error handling and data formatting capabilities for the Web3.js ecosystem. It contains essential error creators and formatters that ensure consistent behavior across all Web3.js sub-packages when interacting with Ethereum nodes.
npm install web3-core-helpersconst { errors, formatters } = require("web3-core-helpers");ES6/TypeScript:
import { errors, formatters } from "web3-core-helpers";const { errors, formatters } = require("web3-core-helpers");
// Create standardized errors
const connectionError = errors.InvalidConnection("wss://localhost:8546");
const paramError = errors.InvalidNumberOfParams(2, 3, "eth_getBalance");
// Format data for Ethereum nodes
const formattedAddress = formatters.inputAddressFormatter("0xd46e8dd67c5d32be8058bb8eb970870f07244567");
const formattedBlockNumber = formatters.inputBlockNumberFormatter("latest");
// Format data from Ethereum nodes
const formattedTransaction = formatters.outputTransactionFormatter({
blockNumber: "0x5bad55",
value: "0xde0b6b3a7640000"
});Web3 Core Helpers is organized around two main functional areas:
Complete error handling system providing standardized error creation for connection issues, validation failures, transaction problems, and contract interactions.
// Connection & Provider Errors
function ErrorResponse(result: Error): Error;
function InvalidConnection(host: string, event?: WebSocketEvent): ConnectionError;
function InvalidProvider(): Error;
function ConnectionTimeout(ms: string): Error;
// Transaction Errors
function TransactionError(message: string, receipt: object): TransactionError;
function RevertInstructionError(reason: string, signature: string): RevertInstructionError;
function TransactionOutOfGasError(receipt: object): TransactionError;
// Contract Errors
function ContractMissingABIError(): Error;
function ContractNoAddressDefinedError(): Error;Comprehensive data formatting utilities for converting between JavaScript types and Ethereum node formats, with separate input and output formatters for different data types.
// Input Formatters (JS -> Ethereum node format)
function inputAddressFormatter(address: string): string;
function inputBlockNumberFormatter(blockNumber: string | number): string | number;
function inputTransactionFormatter(options: object): object;
function txInputFormatter(options: object): object;
function inputSignFormatter(data: string): string;
// Output Formatters (Ethereum node -> JS format)
function outputBigNumberFormatter(number: string | number): string;
function outputTransactionFormatter(tx: object, hexFormat?: boolean): object;
function outputBlockFormatter(block: object, hexFormat?: boolean): object;
function outputLogFormatter(log: object): object;
// Utility Functions
function isPredefinedBlockNumber(blockNumber: string): boolean;interface ConnectionError extends Error {
code: string | undefined;
reason: string | undefined;
}
interface TransactionError extends Error {
receipt: object;
}
interface RevertInstructionError extends Error {
reason: string;
signature: string;
}
interface WebSocketEvent {
code?: number;
reason?: string;
}
interface JsonRpcPayload {
jsonrpc: string;
method: string;
params?: any[];
id?: string | number;
}
interface JsonRpcResponse {
jsonrpc: string;
id: string | number;
result?: any;
error?: {
readonly code?: number;
readonly data?: unknown;
readonly message: string;
};
}