Documentation Index
Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
Use this file to discover all available pages before exploring further.
JSON-RPC error type and standardized error codes following JSON-RPC 2.0 and EIP-1474 specifications.
Type Definition
export interface JsonRpcErrorType {
readonly code: number;
readonly message: string;
readonly data?: unknown;
}
Quick Start
import {
JsonRpcError,
INVALID_INPUT,
RESOURCE_NOT_FOUND,
} from '@tevm/voltaire/JsonRpcError';
// Create error
const error = JsonRpcError.from(INVALID_INPUT, 'execution reverted');
// With additional data
const revertError = JsonRpcError.from(
INVALID_INPUT,
'execution reverted',
'0x08c379a0...' // ABI-encoded revert reason
);
// Format error
const formatted = JsonRpcError.toString(error);
// "[-32000] execution reverted"
Error Code Constants
Standard JSON-RPC 2.0
| Code | Constant | Description |
|---|
-32700 | PARSE_ERROR | Invalid JSON received by server |
-32600 | INVALID_REQUEST | JSON is not a valid request object |
-32601 | METHOD_NOT_FOUND | Method does not exist or is not available |
-32602 | INVALID_PARAMS | Invalid method parameter(s) |
-32603 | INTERNAL_ERROR | Internal JSON-RPC error |
Ethereum-Specific (EIP-1474)
Server error range: -32000 to -32099
| Code | Constant | Description |
|---|
-32000 | INVALID_INPUT | Missing or invalid parameters (commonly “execution reverted”) |
-32001 | RESOURCE_NOT_FOUND | Requested resource not found (block, transaction, etc.) |
-32002 | RESOURCE_UNAVAILABLE | Requested resource not available (node syncing, data not ready) |
-32003 | TRANSACTION_REJECTED | Transaction creation failed |
-32004 | METHOD_NOT_SUPPORTED | Method exists but is not implemented |
-32005 | LIMIT_EXCEEDED | Request exceeds defined limit |
-32006 | JSON_RPC_VERSION_NOT_SUPPORTED | JSON-RPC protocol version not supported |
API Reference
from()
Create error from code and message:
// From code and message
const err1 = JsonRpcError.from(-32000, 'Invalid input');
// With data
const err2 = JsonRpcError.from(-32000, 'execution reverted', '0x...');
// From error object
const err3 = JsonRpcError.from({
code: -32000,
message: 'Invalid input',
data: { reason: 'insufficient gas' }
});
Parameters:
code: number | JsonRpcErrorType - Error code or error object
message?: string - Error message
data?: unknown - Additional error data
Returns: JsonRpcErrorType
toString()
Format error as string:
const error = JsonRpcError.from(-32000, 'execution reverted');
const formatted = JsonRpcError.toString(error);
// "[-32000] execution reverted"
Parameters:
error: JsonRpcErrorType - Error object
Returns: string - Formatted error string
Common Patterns
Execution Reverted
The -32000 error code is most common for contract execution failures:
import { INVALID_INPUT } from '@tevm/voltaire/JsonRpcError';
// Contract call failed
const error = JsonRpcError.from(
INVALID_INPUT,
'execution reverted',
'0x08c379a0...' // ABI-encoded revert reason
);
// Check for execution revert
if (response.error?.code === INVALID_INPUT) {
console.error('Contract reverted:', response.error.data);
}
Error Code Checking
import {
INVALID_INPUT,
RESOURCE_NOT_FOUND,
METHOD_NOT_FOUND,
} from '@tevm/voltaire/JsonRpcError';
function handleError(error: JsonRpcErrorType) {
switch (error.code) {
case INVALID_INPUT:
return 'Invalid input or execution reverted';
case RESOURCE_NOT_FOUND:
return 'Resource not found';
case METHOD_NOT_FOUND:
return 'Method not supported';
default:
return `Error ${error.code}: ${error.message}`;
}
}
Error Messages Lookup
import { ERROR_MESSAGES } from '@tevm/voltaire/JsonRpcError';
const code = -32000;
const defaultMessage = ERROR_MESSAGES[code]; // "Invalid input"
Tree-Shaking
Import only what you need:
// Import specific constants (tree-shakeable)
import {
INVALID_INPUT,
RESOURCE_NOT_FOUND,
TRANSACTION_REJECTED,
} from '@tevm/voltaire/JsonRpcError';
// Import constructors
import { from, toString } from '@tevm/voltaire/JsonRpcError';
Specifications