OpenViSTAI · Agents · Blockchain · Crypto
Menu
Developer Tools

RPC Errors

RPC Errors is a TypeScript library that constructs generic JSON-RPC, Ethereum JSON-RPC and Ethereum Provider errors, and serializes unknown errors into supported formats.

Independent OpenViST project profile, based on linked sources.

RPC Errors — OpenViST project profile in Developer Tools.
OpenViST project illustration. See the linked sources for product details.
Understand the project

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.
Before you choose

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 rpcErrors and providerErrors namespaces.
  • 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.

Source-based practical guide

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

  1. Install the package with the command below or yarn add @metamask/rpc-errors.

    Documented command
    npm install @metamask/rpc-errors
  2. Import rpcErrors and providerErrors from @metamask/rpc-errors.

  3. Use a constructor such as rpcErrors.invalidRequest() or providerErrors.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.
Source-based practical guide

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

  1. Import serializeError from @metamask/rpc-errors.

  2. Pass the error value to serializeError.

  3. 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 message property takes precedence over the fallback message.
  • Without a supplied fallback, the documented fallback is code -32603 and message Internal JSON-RPC error.
Evidence and transparency

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