Skip to main content

Chain Methods API

Account management Snaps can choose to implement the following EVM methods to support dapp requests from custom accounts.

EOA methods​

The following methods are used by externally owned accounts (EOAs).

personal_sign​

Presents a plain text signature challenge to the user and returns the signed response. Equivalent to eth_sign on some other wallets, and prepends a safe prefix to the signed message to prevent the challenge tricking users into signing a financial transaction.

Parameters​

An array containing:

  1. Message to sign: string - Hex-encoded UTF-8 string to present to the user.
  2. Address: string - Address of the requested signing account.

Returns​

Signature: string - Hex-encoded signature.

Example​

{
"method": "personal_sign",
"params": [
"0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765",
"0x5874174dcf1ab6F7Efd8496f4f09404CD1c5bA84"
]
}

eth_signTransaction​

Signs a transaction that can be submitted to the network later using eth_sendRawTransaction.

Parameters​

An array containing:

  1. Transaction object to sign, which contains:
    • type: string - Transaction type.
    • nonce: string - Anti-replay parameter.
    • to: string - Recipient address, or null if this is a contract creation transaction.
    • from: string - Sender address.
    • value: string - Value to be transferred, in wei.
    • data: string - Compiled code of a contract OR hash of the invoked method signature and encoded parameters.
    • gasLimit: string - Gas provided by the sender.
    • gasPrice: string - (Optional) Gas price, in wei, provided by the sender.
    • maxPriorityFeePerGas: string - (Optional) Maximum fee, in wei, the sender is willing to pay per gas above the base fee.
    • maxFeePerGas:string - (Optional) Maximum total fee (base fee + priority fee), in wei, the sender is willing to pay per gas.
    • accessList: object[] - (Optional) List of addresses and storage keys the transaction plans to access.
    • chainId: string - Chain ID.

Returns​

A signature object containing:

  • v: string - ECDSA Recovery ID.
  • r: string - ECDSA signature r.
  • s: string - ECDSA signature s.

Example​

{
"method": "eth_signTransaction",
"params": [
{
"type": "0x2",
"nonce": "0x1",
"to": "0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb",
"from": "0x660265edc169bab511a40c0e049cc1e33774443d",
"value": "0x0",
"data": "0x",
"gasLimit": "0x5208",
"maxPriorityFeePerGas": "0x3b9aca00",
"maxFeePerGas": "0x2540be400",
"accessList": [],
"chainId": "0xaa36a7"
}
]
}

eth_signTypedData_v4​

Presents a data message for the user to sign in a structured and readable format, and returns the signed response. Introduced by EIP-712.

Parameters​

An array containing:

  1. Address: string - Address of the requested signing account.
  2. Typed data: object - Typed data object containing:
    • types: object - Types object containing:
      • EIP712Domain: array - Array specifying one or more of the following domain separator values:
        • name - User-readable name of the signing domain, that is, name of the dapp or the protocol.
        • version - Current major version of the signing domain.
        • chainId - Chain ID of the network.
        • verifyingContract - Address of the contract that will verify the signature.
        • salt - Disambiguating salt for the protocol.
    • primaryType: string - Primary type.
    • domain: object - Domain separator values specified in the EIP712Domain type.
    • message: object - Message to present to the user.

Returns​

Signature: string - Hex-encoded signature.

Example​

{
"method": "eth_signTypedData_v4",
"params": [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
{
"types": {
"EIP712Domain": [
{ "name": "name", "type": "string" },
{ "name": "version", "type": "string" },
{ "name": "chainId", "type": "uint256" },
{ "name": "verifyingContract", "type": "address" }
],
"Person": [
{ "name": "name", "type": "string" },
{ "name": "wallet", "type": "address" }
],
"Mail": [
{ "name": "from", "type": "Person" },
{ "name": "to", "type": "Person" },
{ "name": "contents", "type": "string" }
]
},
"primaryType": "Mail",
"domain": {
"name": "Ether Mail",
"version": "1",
"chainId": 1,
"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
},
"message": {
"from": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
},
"to": {
"name": "Bob",
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
},
"contents": "Hello, Bob!"
}
}
]
}

ERC-4337 methods​

Flask Only
This feature is experimental and only available in MetaMask Flask, the canary distribution of MetaMask.

The following methods are used by ERC-4337 accounts.

eth_prepareUserOperation​

Prepares a new user operation from transaction data.

Parameters​

An array containing:

  1. Transaction intents object, which contains:
    • to: string - Recipient address, or null if this is a contract creation transaction.
    • value: string - Value to be transferred, in wei.
    • data: string - Compiled code of a contract OR hash of the invoked method signature and encoded parameters.

Returns​

A user operation details object containing:

  • callData: string - Data to pass to the sender during the main execution call.
  • initCode: string - Account bytecode (needed if and only if the account is not yet onchain and needs to be created).
  • nonce: string - Anti-replay parameter.
  • gasLimits - (Optional) Gas limits object containing:
    • callGasLimit: string - Amount of gas to allocate to the main execution call.
    • verificationGasLimit: string - Amount of gas to allocate to the verification step.
    • preVerificationGas: string - Amount of gas to compensate the bundler for pre-verification execution, to pay for callData, and to account for overhead that can't be tracked onchain.
  • dummySignature: string - Dummy signature.
  • dummyPaymasterAndData: string - Dummy paymasterAndData.
  • bundlerUrl: string - Bundler URL.

Example​

{
"method": "eth_prepareUserOperation",
"params": [
{
"to": "0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb",
"value": "0x0",
"data": "0x"
},
{
"to": "0x660265edc169bab511a40c0e049cc1e33774443d",
"value": "0x0",
"data": "0x619a309f"
}
]
}

eth_patchUserOperation​

Patches some allowed properties of a user operation.

Parameters​

An array containing:

  1. User operation object, which contains:
    • sender: string - Account making the operation.
    • callData: string - Data to pass to the sender during the main execution call.
    • initCode: string - Account bytecode (needed if and only if the account is not yet onchain and needs to be created).
    • nonce: string - Anti-replay parameter.
    • callGasLimit: string - Amount of gas to allocate to the main execution call.
    • verificationGasLimit: string - Amount of gas to allocate to the verification step.
    • preVerificationGas: string - Amount of gas to compensate the bundler for pre-verification execution, to pay for callData, and to account for overhead that can't be tracked onchain.
    • maxFeePerGas: string - Maximum total fee the sender is willing to pay per gas.
    • maxPriorityFeePerGas: string - Maximum fee the sender is willing to pay per gas above the base fee.
    • paymasterAndData: string - Address of the paymaster sponsoring the transaction, followed by extra data to send to the paymaster (empty for self-sponsored transactions).
    • signature: string - Data passed into the account along with the nonce during the verification step.

Returns​

A partial user operation object containing:

  • paymasterAndData: string - Address of the paymaster sponsoring the transaction, followed by extra data to send to the paymaster (empty for self-sponsored transactions).
  • callGasLimit: string - (Optional) Amount of gas to allocate to the main execution call.
  • verificationGasLimit: string - (Optional) Amount of gas to allocate to the verification step.
  • preVerificationGas: string - (Optional) Amount of gas to compensate the bundler for pre-verification execution, to pay for callData, and to account for overhead that can't be tracked onchain.

Example​

{
"method": "eth_patchUserOperation",
"params": [
{
"sender": "0x4584d2B4905087A100420AFfCe1b2d73fC69B8E4",
"nonce": "0x1",
"initCode": "0x",
"callData": "0x70641a22000000000000000000000000f3de3c0d654fda23dad170f0f320a921725091270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e49871efa4000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000067fd192000000000000000000000000000000000000000001411a0c3b763237f484fdd70000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000280000000000000003b6d03400d4a11d5eeaac28ec3f61d100daf4d40471f185280000000000000003b6d03408f1b19622a888c53c8ee4f7d7b4dc8f574ff906800000000000000000000000000000000000000000000000000000000",
"callGasLimit": "0x58a83",
"verificationGasLimit": "0xe8c4",
"preVerificationGas": "0xc57c",
"maxFeePerGas": "0x87f0878c0",
"maxPriorityFeePerGas": "0x1dcd6500",
"paymasterAndData": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"signature": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
}
]
}

eth_signUserOperation​

Signs a user operation.

Parameters​

An array containing:

  1. User operation object, which contains:
    • sender: string - Account making the operation.
    • callData: string - Data to pass to the sender during the main execution call.
    • initCode: string - Account bytecode (needed if and only if the account is not yet onchain and needs to be created).
    • nonce: string - Anti-replay parameter.
    • callGasLimit: string - Amount of gas to allocate to the main execution call.
    • verificationGasLimit: string - Amount of gas to allocate to the verification step.
    • preVerificationGas: string - Amount of gas to compensate the bundler for pre-verification execution, to pay for callData, and to account for overhead that can't be tracked onchain.
    • maxFeePerGas: string - Maximum total fee the sender is willing to pay per gas.
    • maxPriorityFeePerGas: string - Maximum fee the sender is willing to pay per gas above the base fee.
    • paymasterAndData: string - Address of the paymaster sponsoring the transaction, followed by extra data to send to the paymaster (empty for self-sponsored transactions).
    • signature: string - Data passed into the account along with the nonce during the verification step.
  2. Entry point: string - Hash of the entry point contract.

Returns​

Signature: string - Hex-encoded signature.

Example​

{
"method": "eth_signUserOperation",
"params": [
{
"sender": "0x4584d2B4905087A100420AFfCe1b2d73fC69B8E4",
"nonce": "0x1",
"initCode": "0x",
"callData": "0x70641a22000000000000000000000000f3de3c0d654fda23dad170f0f320a921725091270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e49871efa4000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000067fd192000000000000000000000000000000000000000001411a0c3b763237f484fdd70000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000280000000000000003b6d03400d4a11d5eeaac28ec3f61d100daf4d40471f185280000000000000003b6d03408f1b19622a888c53c8ee4f7d7b4dc8f574ff906800000000000000000000000000000000000000000000000000000000",
"callGasLimit": "0x58a83",
"verificationGasLimit": "0xe8c4",
"preVerificationGas": "0xc57c",
"maxFeePerGas": "0x87f0878c0",
"maxPriorityFeePerGas": "0x1dcd6500",
"paymasterAndData": "0x952514d7cBCB495EACeB86e02154921401dB0Cd9dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000779b3fbb00000000000000006565b267000000000000000000000000000000000000000029195b31a9b1c6ccdeff53e359ebbcd5f075a93c1aaed93302e5fde5faf8047028b296b8a3fa4e22b063af5069ae9f656736ffda0ee090c0311155722b905f781b",
"signature": "0x"
},
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
]
}