This page demonstrates how to sign EIP712 typed data using MetaMask and verify it in Solidity. Feel free to learn from it and adapt it for your dApp and smart contracts.

Thank you to Christoph Mussenbrock for Solidity 0.5.0 and variable chain ID support, Dan Finlay for EIP1102 support, and Kieran Mesquita for EIP1193 support.

To use this demo, you need at least version 4.14.0 of MetaMask which supports eth_signTypedData_v3.

Next, copy and paste this into Remix, deploy it in the Javascript VM environment, and run the verify function.

The signature generated by MetaMask, as well as your wallet address, has been inserted into the Solidity code above. The code hashes the data you just signed, runs ecrecover with your signature, and compares it with your wallet address.

If Remix displays

0: bool: true
that's great! Your wallet address was successfully authenticated against the signature.

An example: