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

hex encoded address

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


TypedData object
required

TypedData

types object
required

EIP712Domain array

An array specifying one or more of the following domain separator values: 1) name - The user-readable name of the signing domain, that is, the name of the dapp or the protocol. 2) version - The current major version of the signing domain. 3) chainId - The chain ID of the network. 4) verifyingContract - The address of the contract that will verify the signature. 5) salt - A disambiguating salt for the protocol.

object

name string

type string

domain object

Contains the domain separator values specified in the EIP712Domain type.

primaryType string

message object

The message you're proposing the user to sign.

Returns

Signature string

hex encoded bytes

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

Customize request
Parameter
Value
string
{ "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" } ] } }
object
{ "domain": { "name": "Ether Mail", "version": "1", "chainId": 1, "verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC" } }
object
string
{ "message": { "from": { "name": "Cow", "wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" }, "to": { "name": "Bob", "wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" }, "contents": "Hello, Bob!" } }
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"