Skip to main content

Sign data

Since MetaMask makes cryptographic keys available to each user, websites can use these signatures for a variety of uses. Here are a few guides related to specific use cases:

There are currently six signing methods:

  • eth_sign
  • personal_sign
  • signTypedData (currently identical to signTypedData_v1)
  • signTypedData_v1
  • signTypedData_v3
  • signTypedData_v4

We recommend using signTypedData_v4 for most use cases. Read more about the history of the signing methods.

note

MetaMask supports signing transactions with Trezor and Ledger hardware wallets. These hardware wallets currently only support signing data using the personal_sign method. If you have trouble logging in to a website or dapp when using a Ledger or Trezor, the site may be requesting you to sign data via an unsupported method, in which case we recommend using your standard MetaMask account.

Sign typed data message parameters

  • domain: Domain or domain signature. This:
    • Is only accepted for a specific website/contract.
    • Makes sure signatures are valid only where they are intended to be valid.
    • Allows you to have a unique contract that verifies the address.
    • Is a bunch of information that restricts where the signature is valid.
    • Is the domain of validity. It could be a contract, URL, etc.
    • Contains specifically what the dapp tells you.
    • Makes sure your signature(s) don't collide with other signatures.
  • chainId: Chain ID. This makes sure signatures signed on one chain aren't valid on another chain.
  • name: This parameter is primarily for UX purposes. For example, as a user, if you're using an Ether Mail app and a dialog comes up for Cryptokitties exchange, this would arouse suspicion due to what the name is on the signature.
  • verifyingContract: This is an extra layer of assurance. Even if two developers end up creating an app with the same name, they will never have the same contract address. If you're unsure of the name, this shows the contract responsible for message verification. This field also takes a URL.
  • version: Current version of the domain object.
  • message: This parameter is completely open to any structure. Every field is optional.

Example

This is an example of signing typed data with MetaMask. See the reference.

<div>
<h3>Sign Typed Data V4</h3>
<button type="button" id="signTypedDataV4Button">sign typed data v4</button>
</div>