Skip to main content
MetaMask
Restricted
Multichain API

eth_signTypedData_v4

Summary: Presents a structured data message for the user to sign.

Presents a data message for the user to sign in a structured and readable format and returns the signed response. Introduced by EIP-712. This method requires that the user has granted permission to interact with their account first, so make sure to call eth_requestAccounts (recommended) or wallet_requestPermissions first.

Parameters

Address
string
required

The address of the requested signing account.

Pattern: ^0x[0-9a-fA-F]{40}$


Typed data
object
required

Object containing information about the typed data to sign.

types
object
required

Object containing type information.

EIP712Domain
array

An array specifying one or more of the following domain separator values:

  • name - The user-readable name of the signing domain, that is, the name of the dapp or the protocol.
  • version - The current major version of the signing domain.
  • chainId - The chain ID of the network.
  • verifyingContract - The address of the contract that will verify the signature.
  • salt - A disambiguating salt for the protocol.

Domain separator value
object

Object containing information about the domain separator value.

name
string

Name of the domain separator value.

type
string

Data type of the domain separator value.

domain
object

Object containing the domain separator values specified in the EIP712Domain type.

primaryType
string

The primary type of the message.

message
object

The message you're proposing the user to sign.

Returns

Signature
string

A hex-encoded signature.

Pattern: ^0x[0-9a-f]*$

Customize request
Parameter
Value
string
{ "types": { "EIP712Domain": [] } }
object
[]
array
{ "domain": {} }
object
string
{ "message": {} }
object

Connect your MetaMask wallet to run requests successfully.

Request

await window.ethereum.request({
"method": "eth_signTypedData_v4",
"params": [
"0x0000000000000000000000000000000000000000",
{
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!"
}
}
],
});

Example response

"0x4355c47d63924e8a72e509b65029052eb6c299d53a04e167c5775fd466751c9d07299936d304c153f6443dfa05f40ff007d72911b6f72307f996231605b915621c"