Gathering detailed insights and metrics for eth-rpc-ers
Gathering detailed insights and metrics for eth-rpc-ers
Gathering detailed insights and metrics for eth-rpc-ers
Gathering detailed insights and metrics for eth-rpc-ers
npm install eth-rpc-ers
Typescript
Module System
Node Version
NPM Version
20.3
Supply Chain
96.5
Quality
75.4
Maintenance
100
Vulnerability
100
License
TypeScript (69.77%)
JavaScript (29.42%)
Shell (0.81%)
Total Downloads
130
Last Day
1
Last Week
2
Last Month
13
Last Year
130
MIT License
171 Stars
147 Commits
36 Forks
70 Watchers
5 Branches
297 Contributors
Updated on Jul 03, 2025
Minified
Minified + Gzipped
Latest Version
2.0.2
Package Id
eth-rpc-ers@2.0.2
Unpacked Size
12.09 kB
Size
5.05 kB
File Count
5
NPM Version
10.7.0
Node Version
20.15.0
Published on
Oct 31, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
100%
2
Compared to previous week
Last Month
62.5%
13
Compared to previous month
Last Year
0%
130
Compared to previous year
3
4
Errors for the Ethereum JSON RPC and Ethereum Provider, and making unknown errors compliant with either spec.
1import { ethErrors } from 'eth-json-rpc-errors' 2 3throw ethErrors.provider.unauthorized() 4// or 5throw ethErrors.provider.unauthorized('my custom message')
CloseEvent
errors or status codes.Installation: npm install eth-json-rpc-errors
or yarn add eth-json-rpc-errors
Import using ES6 syntax (no default export) or Node require
.
1import { ethErrors } from 'eth-json-rpc-errors' 2 3// Ethereum RPC errors are namespaced under "ethErrors.rpc" 4response.error = ethErrors.rpc.methodNotFound({ 5 message: optionalCustomMessage, data: optionalData 6}) 7 8// ETH JSON RPC errors namespaced under ethErrors.provider 9response.error = ethErrors.provider.unauthorized({ 10 message: optionalCustomMessage, data: optionalData 11}) 12 13// each error getter takes a single "opts" argument 14// for most errors, this can be replaced with a single string, which becomes 15// the error message 16response.error = ethErrors.provider.unauthorized(customMessage) 17 18// if an error getter accepts a single string, all arguments can be omitted 19response.error = ethErrors.provider.unauthorized() 20response.error = ethErrors.provider.unauthorized({}) 21 22// omitting the message will produce an error with a default message per 23// the relevant spec 24 25// omitting the data argument will produce an error without a 26// "data" property 27 28// the JSON RPC 2.0 server error requires a valid code 29response.error = ethErrors.rpc.server({ 30 code: -32031 31}) 32 33// custom Ethereum Provider errors require a valid code and message 34// valid codes are integers i such that: 1000 <= i <= 4999 35response.error = ethErrors.provider.custom({ 36 code: 1001, message: 'foo' 37})
1// this is useful for ensuring your errors are standardized 2import { serializeError } from 'eth-json-rpc-errors' 3 4// if the argument is not a valid error per any supported spec, 5// it will be added as error.data.originalError 6response.error = serializeError(maybeAnError) 7 8// you can add a custom fallback error code and message if desired 9const fallbackError = { code: 4999, message: 'My custom error.' } 10response.error = serializeError(maybeAnError, fallbackError) 11 12// Note: if the original error has a "message" property, it will take 13// precedence over the fallback error's message 14 15// the default fallback is: 16{ 17 code: -32603, 18 message: 'Internal JSON-RPC error.' 19}
1/**
2 * TypeScript interfaces
3 */
4import {
5 // these describe to the corresponding exports from index.js
6 IEthErrors, IEthereumRpcError, IEthereumProviderError, ISerializeError,
7 // these describe the options argument to error getters in ethErrors
8 IErrorOptions, IRpcServerErrorOptions, IProviderCustomErrorOptions
9} from 'eth-json-rpc-errors/@types'
10
11/**
12 * Classes
13 */
14import { EthereumRpcError, EthereumProviderError } from 'eth-json-rpc-errors'
15
16/**
17 * getMessageFromCode & ERROR_CODES
18 */
19import { getMessageFromCode, ERROR_CODES } from 'eth-json-rpc-errors'
20
21// get the default message string for the given code, or a fallback message if
22// no message exists for the given code
23const message1 = getMessageFromCode(someCode)
24
25// you can specify your own fallback message
26const message2 = getMessageFromCode(someCode, myFallback)
27// it can be anything, use at your own peril
28const message3 = getMessageFromCode(someCode, null)
29
30// {
31// jsonRpc: { [errorName]: code, ... },
32// eth: { [errorName]: code, ... },
33// }
34const code1 = ERROR_CODES.rpc.parse
35const code2 = ERROR_CODES.provider.userRejectedRequest
36
37// all codes in ERROR_CODES have default messages
38const message4 = getMessageFromCode(code1)
39const message5 = getMessageFromCode(code2)
MIT
No vulnerabilities found.
No security vulnerabilities found.