forked from DePayFi/web3-wallets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
342 lines (327 loc) · 19.3 KB
/
demo.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" href="https://depay.com/favicon.png"/>
<title>Development</title>
<link rel="stylesheet" href="https://unpkg.com/bootstrap@5/dist/css/bootstrap.css">
<script src="https://cdn.ethers.io/lib/ethers-5.6.umd.min.js" type="application/javascript"></script>
<script crossorigin src="https://unpkg.com/@depay/solana-web3.js@1"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-blockchains@6"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-constants@6"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-client@10"></script>
<script crossorigin src="https://unpkg.com/@depay/walletconnect-v1@1"></script>
<script crossorigin src="https://unpkg.com/@depay/coinbase-wallet-sdk@1"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-tokens@9"></script>
<script src="dist/umd/index.js"></script>
<style>
.btn-primary {
color: #fff;
background-color: #ea357a !important;
border: 1px solid #ea357a !important;
padding: 0.35rem 1.2rem !important;
box-shadow: none;
outline: none;
}
.btn-primary:hover {
background-color: #db3071 !important;
}
</style>
</head>
<body style="background-color: #FAFAFA;">
<div class="container py-4">
<div class="py-2 pb-3 text-center">
<a href="https://depay.com" target="_blank">
<img alt="DePay" class="navbar-logo shadow-sm" src="https://depay.com/logo.svg" style="height: 50px; width: 50px; border-radius: 999px;"/>
</a>
</div>
<div class="row px-2">
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">getWallets()</h5>
<div class="px-4">
<div class="text-secondary ">Retrieve all available wallets.</div>
<div class="text-secondary ">(check console.log)</div>
</div>
</div>
<div class="px-4 pt-3">
<button class='btn btn-primary' onClick='console.log(Web3Wallets.getWallets())'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">wallet.connect()</h5>
<div class="px-4">
<div class="text-secondary pb-2">Connect detected wallet and yield connected account.</div>
<select id="connectWallet">
</select>
<script>
document.addEventListener("DOMContentLoaded", function() {
let select = document.getElementById('connectWallet')
Web3Wallets.getWallets().forEach((wallet, index)=>{
let option = document.createElement("option")
option.setAttribute('value', index)
option.innerHTML = wallet.name
select.append(option)
})
})
window.connectWalletViaSelect = async ()=> {
let wallet = Web3Wallets.getWallets()[parseInt(document.getElementById("connectWallet").value, 10)]
let accounts = await wallet.connect()
window.wallet = wallet
console.log(accounts)
}
</script>
</div>
</div>
<div class="px-4 pt-3">
<button class='btn btn-primary' onClick='connectWalletViaSelect()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">WalletConnect connect</h5>
<div class="px-4">
<div class="text-secondary ">Test connecting WalletConnect.</div>
</div>
</div>
<div class="px-4 pt-3">
<script>
window.connectWalletConnect = ()=>{
wallet = new Web3Wallets.wallets.WalletConnect()
wallet.connect()
}
</script>
<button class='btn btn-primary' onClick='connectWalletConnect()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Coinbase WalletLink connect</h5>
<div class="px-4">
<div class="text-secondary ">Test connecting Coinbase WalletLink.</div>
</div>
</div>
<div class="px-4 pt-3">
<script>
window.connectWalletLink = ()=> {
wallet = new Web3Wallets.wallets.WalletLink()
wallet.connect()
}
</script>
<button class='btn btn-primary' onClick='connectWalletLink()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Connected account</h5>
<div class="px-4">
<div class="text-secondary">Provides connected account via wallet</div>
</div>
</div>
<div class="px-4 pt-3">
<script>
window.account = async()=>{ console.log(await window.wallet.account()) }
</script>
<button class='btn btn-primary' onClick='window.account()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Account changed event</h5>
<div class="px-4">
<div class="text-secondary">Executes callback function in case account changes.</div>
</div>
</div>
<div class="px-4 pt-3">
<script>
window.setupAccountChanged = async function(){
window.wallet.on('account', (newAccount)=>{
alert(newAccount)
})
alert('Now change the wallet account!')
}
</script>
<button class='btn btn-primary' onClick='window.setupAccountChanged()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Send simple SOL transfer on Solana</h5>
</div>
<div class="px-4 pt-3">
<script>
window.sendSimpleSOLTransfer = async ()=> {
console.log('sendSimpleSOLTransfer')
window.wallet.sendTransaction({
blockchain: "solana",
to: "5AcFMJZkXo14r3Hj99iYd1HScPiM4hAcLZf552DfZkxa",
from: await window.wallet.account(),
value: 0.01,
sent: function(transaction){ console.log("sent callback", transaction) },
confirmed: function(transaction){ console.log("confirmed callack", transaction) },
failed: function(transaction){ console.log("failed callack", transaction) }
})
}
</script>
<button class='btn btn-primary' onClick='window.sendSimpleSOLTransfer()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Send Solana instruction(s)</h5>
<div class="px-4">
<div class="text-secondary ">e.g. transfer 1 USDC</div>
</div>
</div>
<div class="px-4 pt-3">
<script>
window.sendUSDCSolana = async ()=> {
console.log('sendUSDCSolana')
let from = await window.wallet.account()
window.wallet.sendTransaction({
blockchain: "solana",
from,
instructions: [await Web3Tokens.Token.solana.createTransferInstruction({
token: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
amount: '1000000',
from,
to: '5AcFMJZkXo14r3Hj99iYd1HScPiM4hAcLZf552DfZkxa'
})],
sent: function(transaction){ console.log("sent callback", transaction) },
confirmed: function(transaction){ console.log("confirmed callack", transaction) },
failed: function(transaction){ console.log("failed callack", transaction) }
})
}
</script>
<button class='btn btn-primary' onClick='window.sendUSDCSolana()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Send simple BNB transfer bsc</h5>
</div>
<div class="px-4 pt-3">
<script>
window.sendSimpleTransferBsc = async ()=> {
console.log('sendSimpleTransferBsc')
wallet.sendTransaction({
blockchain: "bsc",
to: "0x08B277154218CCF3380CAE48d630DA13462E3950",
value: "1000000000000000",
sent: function(transaction){ console.log("sent callack", transaction) },
confirmed: function(transaction){ console.log("confirmed callack", transaction) },
failed: function(transaction){ console.log("failed callack", transaction) }
})
}
</script>
<button class='btn btn-primary' onClick='window.sendSimpleTransferBsc()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Send simple BNB transfer into smart contract bsc</h5>
<div class="px-4">
<div class="text-secondary ">Should have elavated gas limit.</div>
</div>
</div>
<div class="px-4 pt-3">
<script>
window.sendSimpleTransferBscIntoContract = async ()=> {
console.log('sendSimpleTransferBscIntoContract')
wallet.sendTransaction({
blockchain: "bsc",
to: "0xb6c3ea7940bb9d99bc968d41e6fa06e07402ed43",
from: await wallet.account(),
value: "1000000000000000"
})
}
</script>
<button class='btn btn-primary' onClick='window.sendSimpleTransferBscIntoContract()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Send BUSD token transfer bsc</h5>
</div>
<div class="px-4 pt-3">
<script>
window.sendContractTransactionBsc = async ()=> {
console.log('sendContractTransactionBsc')
await wallet.sendTransaction({
blockchain: "bsc",
from: await wallet.account(),
to: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",
method: "transfer",
params: ["0x317D875cA3B9f8d14f960486C0d1D1913be74e90", "1000000000000000000" ],
api: [{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}],
})
}
</script>
<button class='btn btn-primary' onClick='window.sendContractTransactionBsc()'>Try it</button>
</div>
</div>
</div>
</div>
<div class="d-block d-md-inline-block p-2 col-12 col-md-4">
<div class="px-0 py-4 rounded-lg bg-white border">
<div class="col px-0">
<div class="overflow-auto" style="height: 120px;">
<h5 class="px-4">Sign message</h5>
<div class="px-4">
<div class="text-secondary ">Test signing a msg through the connected wallet.</div>
</div>
</div>
<div class="px-4 pt-3">
<button class='btn btn-primary' onClick='window.wallet.sign("This is a test message\n\n And a new line").then((signature)=>{console.log(signature)})'>Try it</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>