5

Metamask errors are handled using a JSON object with two fields.

  1. Error Code (code)
  2. Error Message (message)

Example if a user denies to sign a transaction:

{code: 4001, message: "MetaMask Tx Signature: User denied transaction signature."}

There does not seem to be a comprehensive list of possible error codes on the official Metamask docs.

I would like a comprehensive list, so I can implement it into my application and handle any possible error that metamask can detect.

Does a comprehensive list of all possible Metamask error codes exist?

1

2 Answers 2

6

Yes there is an official list. And here is an example implementation in Javascript JSON format:

const METAMASK_POSSIBLE_ERRORS = 
{
    '-32700': 
    {
        standard: 'JSON RPC 2.0',
        message: 'Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.',
    },
    '-32600': 
    {
        standard: 'JSON RPC 2.0',
        message: 'The JSON sent is not a valid Request object.',
    },
    '-32601': 
    {
        standard: 'JSON RPC 2.0',
        message: 'The method does not exist / is not available.',
    },
    '-32602': 
    {
        standard: 'JSON RPC 2.0',
        message: 'Invalid method parameter(s).',
    },
    '-32603': 
    {
        standard: 'JSON RPC 2.0',
        message: 'Internal JSON-RPC error.',
    },
    '-32000': 
    {
        standard: 'EIP-1474',
        message: 'Invalid input.',
    },
    '-32001': 
    {
        standard: 'EIP-1474',
        message: 'Resource not found.',
    },
    '-32002': 
    {
        standard: 'EIP-1474',
        message: 'Resource unavailable.',
    },
    '-32003': 
    {
        standard: 'EIP-1474',
        message: 'Transaction rejected.',
    },
    '-32004': 
    {
        standard: 'EIP-1474',
        message: 'Method not supported.',
    },
    '-32005': 
    {
        standard: 'EIP-1474',
        message: 'Request limit exceeded.',
    },
    '4001': 
    {
        standard: 'EIP-1193',
        message: 'User rejected the request.',
    },
    '4100': 
    {
        standard: 'EIP-1193',
        message: 'The requested account and/or method has not been authorized by the user.',
    },
    '4200': 
    {
        standard: 'EIP-1193',
        message: 'The requested method is not supported by this Ethereum provider.',
    },
    '4900': 
    {
        standard: 'EIP-1193',
        message: 'The provider is disconnected from all chains.',
    },
    '4901': 
    {
        standard: 'EIP-1193',
        message: 'The provider is disconnected from the specified chain.',
    },
}
0

All errors thrown or returned by the MetaMask provider follow this interface:

interface ProviderRpcError extends Error {
  message: string;
  code: number;
  data?: unknown;
}

The ethereum.request(args) method throws errors eagerly. You can often use the error code property to determine why the request failed. Common codes and their meaning include:

4001 : The request was rejected by the user

-32602: The parameters were invalid

-32603: Internal error

For the complete list of errors, please see EIP-1193 and EIP-1474

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.