Practical overview
When it fits
Use it when application code needs to construct or standardize errors for JSON-RPC 2.0, Ethereum JSON-RPC or the Ethereum Provider interface.
Who it is for
- Developers building TypeScript applications that produce JSON-RPC responses.
- Teams implementing Ethereum provider interfaces that need specification-aligned errors.
Documented uses
- Create predefined JSON-RPC and Ethereum provider errors.
- Set custom error messages and, where supported, attach data.
- Normalize unknown errors into a supported error format.
- Retrieve default messages or error codes through the documented exports.
Requirements & limits
The package is available from its public GitHub repository under the MIT license; installation instructions use npm or Yarn.
- Error constructors are separated into
rpcErrorsandproviderErrorsnamespaces. - Custom server and provider errors have explicit code requirements.
- Unknown errors can be serialized, with an optional fallback code and message.
- CloseEvent errors and status codes are not yet supported.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install RPC Errors and construct a standard error
Add a predefined JSON-RPC or Ethereum provider error to application code.
Before you start
- A TypeScript application
- npm or Yarn
Steps
Install the package with the command below or
yarn add @metamask/rpc-errors.npm install @metamask/rpc-errorsImport
rpcErrorsandproviderErrorsfrom@metamask/rpc-errors.Use a constructor such as
rpcErrors.invalidRequest()orproviderErrors.unauthorized('my custom message').
Expected outcome
Application code can construct an error from the library’s JSON-RPC or provider error families.
Guide limitations
- The documentation does not yet support CloseEvent errors or status codes.
- Custom provider errors require a valid integer code from 1000 through 4999 and a message.
Normalize an unknown error
Convert an application error into a supported JSON-RPC or provider-compliant error representation.
Before you start
- The package installed in the application
- An error value to pass to
serializeError
Steps
Import
serializeErrorfrom@metamask/rpc-errors.Pass the error value to
serializeError.If desired, provide a fallback object with a code and message as the second argument.
Expected outcome
The returned error is standardized; for an input that matches no supported specification, the original error is placed in `error.data.originalError`.
Guide limitations
- An original error's
messageproperty takes precedence over the fallback message. - Without a supplied fallback, the documented fallback is code -32603 and message
Internal JSON-RPC error.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 13 October 2026
- Original website title
- MetaMask/rpc-errors · Official homepage title · retained in its source language

