-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
54 lines (46 loc) · 1.65 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>EIP712 demo</title>
</head>
<body>
<p>
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.
</p>
<p>
Thank you to Christoph Mussenbrock for Solidity 0.5.0 and variable chain ID support, and Dan Finlay for EIP1102 support.
</p>
<p>
To use this demo, you need at least version 4.14.0 of MetaMask which supports eth_signTypedData_v3.
</p>
<button id="signBtn">Click here to sign some typed data</button>
<br />
<p>
Next, copy and paste this
into <a target="_blank" href="https://remix.ethereum.org/#optimize=true&version=soljson-v0.4.24+commit.e67f0147.js">Remix</a>, deploy
it in the Javascript VM environment, and run the verify function.
</p>
<br />
<textarea readonly rows=10 cols=80 id="response">
</textarea>
<br />
<p>
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 yoour signature, and compares it with
your wallet address.
</p>
<p>
If Remix displays <pre>0: bool: true</pre> that's great! Your wallet
address was successfully authenticated against the signature.
</p>
<br />
<p>An example:</p>
<img src="./remix.png" />
<script src="./solidityCode.js" language="javascript"></script>
<script src="./sign.js" language="javascript"></script>
</body>
</html>