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
requiredTypedData
Returns
Signature string
hex encoded bytes
Pattern: ^0x[0-9a-f]*$
Customize request
Parameter
Value
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"