-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathethers_test.html
More file actions
42 lines (36 loc) · 1.16 KB
/
ethers_test.html
File metadata and controls
42 lines (36 loc) · 1.16 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Ethers Test</title>
<!-- Load ethers.js from CDN -->
<script src="https://cdn.jsdelivr.net/npm/ethers@6.13.2/dist/ethers.umd.min.js"></script>
</head>
<body>
<h2>MetaMask Signature Test</h2>
<button id="sign">Sign Message</button>
<script>
document.getElementById("sign").onclick = async () => {
if (!window.ethereum) {
alert("MetaMask not found. Please install it.");
return;
}
try {
// Connect to provider
const provider = new ethers.BrowserProvider(window.ethereum);
await window.ethereum.request({ method: "eth_requestAccounts" });
// Get signer
const signer = await provider.getSigner();
// Replace this with your backend-provided nonce
const nonce = "b09487af2b002015fe7d98031914dff7aaebd9308fa00b985bcc54424aacd53b";
// Ask MetaMask to sign
const signature = await signer.signMessage(nonce);
console.log("Signature:", signature);
alert("Signature: " + signature);
} catch (err) {
console.error(err);
alert("Error: " + err.message);
}
};
</script>
</body>
</html>