-
Notifications
You must be signed in to change notification settings - Fork 0
/
dapp_connect_to_wallet_test.html
84 lines (74 loc) · 2.32 KB
/
dapp_connect_to_wallet_test.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html>
<head>
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.js"></script>
<style>
#resp-table {
display: table;
}
#resp-table-body{
display: table-row-group;
}
.resp-table-row{
display: table-row;
}
.table-body-cell{
display: table-cell;
padding: 8px;
line-height: 1.42857143;
vertical-align: top;
}
</style>
</head>
<body>
<script>
const getEthereumProvider = async () => {
if ("ethereum" in window) {
await window.ethereum.enable(); // opens wallet to connect to
const provider = window.ethereum;
if (provider.isBraveWallet) {
console.log("Is Brave installed? ", provider.isBraveWallet);
return provider;
}
} else {
document.write('Install Brave wallet');
}
};
const getSolanaProvider = async () => {
if ("solana" in window) {
await window.solana.connect(); // opens wallet to connect to
const provider = window.solana;
if (provider.isBraveWallet) {
console.log("Is Brave installed? ", provider.isBraveWallet);
return provider;
}
} else {
document.write('Install Brave wallet');
}
};
const connect = (provider) => {
provider.then(provider => {
console.log('key', provider.publicKey.toString())
})
.catch(function(error){
console.log(error)
});
}
</script>
<div id="resp-table">
<div id="resp-table-body">
<div class="resp-table-row">
<div class="table-body-cell">
<button onClick="connect(getSolanaProvider())">Connect SOL</button>
</div>
<div class="table-body-cell">Click to connect as Solana Dapp</div>
</div>
<div class="resp-table-row">
<div class="table-body-cell">
<button onClick="connect(getEthereumProvider())">Connect ETH</button>
</div>
<div class="table-body-cell">Click to connect as Ethereum Dapp</div>
</div>
</div>
</div>
</body>
</html>