-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetamask.html
34 lines (32 loc) · 1.22 KB
/
metamask.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connect to MetaMask</title>
</head>
<body>
<h2>MetaMask Wallet Connection</h2>
<button id="connectButton">Connect to MetaMask</button>
<p id="account"></p>
<script>
const connectButton = document.getElementById('connectButton');
const accountParagraph = document.getElementById('account');
connectButton.addEventListener('click', async () => {
if (typeof window.ethereum !== 'undefined') {
try {
// Request account access
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
accountParagraph.innerText = `Connected Account: ${account}`;
} catch (error) {
console.error('Error connecting to MetaMask', error);
accountParagraph.innerText = `Error: ${error.message}`;
}
} else {
accountParagraph.innerText = "MetaMask is not installed!";
}
});
</script>
</body>
</html>