-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
53 lines (47 loc) · 1.33 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
<!doctype html>
<html>
<head>
<title>Hello, Snaps!</title>
</head>
<body>
<h1>Hello, Snaps!</h1>
<button class="connect">Connect</button>
<button class="getPubkey">Get public key</button>
<script>
const snapId = `local:${window.location.href}`;
const connectButton = document.querySelector('button.connect')
const sendButton = document.querySelector('button.sendHello')
const getPubkeyButton = document.querySelector('button.getPubkey')
connectButton.addEventListener('click', connect)
getPubkeyButton.addEventListener('click', getPubkey)
// here we get permissions to interact with and install the snap
async function connect () {
await ethereum.request({
method: 'wallet_requestSnaps',
params: { [snapId]: {} }
})
}
async function getPubkey () {
try {
const response = await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId,
request: {
method: 'getPublicKey',
params: {
derivationPath: [`0'`, `0'`],
confirm: true
}
}
}
})
console.log(response);
} catch (err) {
console.error(err)
alert('Problem happened: ' + err.message || err)
}
}
</script>
</body>
</html>