Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
eth-json-rpc-errors
Advanced tools
Errors for the Ethereum JSON RPC and Ethereum Provider, and making unknown errors compliant with either spec.
import { ethErrors } from 'eth-json-rpc-errors'
throw ethErrors.provider.unauthorized()
// or
throw 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
.
import { ethErrors } from 'eth-json-rpc-errors'
// Ethereum RPC errors are namespaced under "ethErrors.rpc"
response.error = ethErrors.rpc.methodNotFound({
message: optionalCustomMessage, data: optionalData
})
// ETH JSON RPC errors namespaced under ethErrors.provider
response.error = ethErrors.provider.unauthorized({
message: optionalCustomMessage, data: optionalData
})
// each error getter takes a single "opts" argument
// for most errors, this can be replaced with a single string, which becomes
// the error message
response.error = ethErrors.provider.unauthorized(customMessage)
// if an error getter accepts a single string, all arguments can be omitted
response.error = ethErrors.provider.unauthorized()
response.error = ethErrors.provider.unauthorized({})
// omitting the message will produce an error with a default message per
// the relevant spec
// omitting the data argument will produce an error without a
// "data" property
// the JSON RPC 2.0 server error requires a valid code
response.error = ethErrors.rpc.server({
code: -32031
})
// custom Ethereum Provider errors require a valid code and message
// valid codes are integers i such that: 1000 <= i <= 4999
response.error = ethErrors.provider.custom({
code: 1001, message: 'foo'
})
// this is useful for ensuring your errors are standardized
import { serializeError } from 'eth-json-rpc-errors'
// if the argument is not a valid error per any supported spec,
// it will be added as error.data.originalError
response.error = serializeError(maybeAnError)
// you can add a custom fallback error code and message if desired
const fallbackError = { code: 4999, message: 'My custom error.' }
response.error = serializeError(maybeAnError, fallbackError)
// Note: if the original error has a "message" property, it will take
// precedence over the fallback error's message
// the default fallback is:
{
code: -32603,
message: 'Internal JSON-RPC error.'
}
/**
* TypeScript interfaces
*/
import {
// these describe to the corresponding exports from index.js
IEthErrors, IEthereumRpcError, IEthereumProviderError, ISerializeError,
// these describe the options argument to error getters in ethErrors
IErrorOptions, IRpcServerErrorOptions, IProviderCustomErrorOptions
} from 'eth-json-rpc-errors/@types'
/**
* Classes
*/
import { EthereumRpcError, EthereumProviderError } from 'eth-json-rpc-errors'
/**
* getMessageFromCode & ERROR_CODES
*/
import { getMessageFromCode, ERROR_CODES } from 'eth-json-rpc-errors'
// get the default message string for the given code, or a fallback message if
// no message exists for the given code
const message1 = getMessageFromCode(someCode)
// you can specify your own fallback message
const message2 = getMessageFromCode(someCode, myFallback)
// it can be anything, use at your own peril
const message3 = getMessageFromCode(someCode, null)
// {
// jsonRpc: { [errorName]: code, ... },
// eth: { [errorName]: code, ... },
// }
const code1 = ERROR_CODES.rpc.parse
const code2 = ERROR_CODES.provider.userRejectedRequest
// all codes in ERROR_CODES have default messages
const message4 = getMessageFromCode(code1)
const message5 = getMessageFromCode(code2)
MIT
FAQs
Ethereum JSON RPC and Provider errors.
The npm package eth-json-rpc-errors receives a total of 10,259 weekly downloads. As such, eth-json-rpc-errors popularity was classified as popular.
We found that eth-json-rpc-errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.