@depay/web3-wallets-svm 18.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 DePay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,519 @@
1
+ ## Quickstart
2
+
3
+ ```
4
+ yarn add @depay/web3-wallets
5
+ ```
6
+
7
+ or
8
+
9
+ ```
10
+ npm install --save @depay/web3-wallets
11
+ ```
12
+
13
+ ```javascript
14
+ import { getWallets } from '@depay/web3-wallets'
15
+
16
+ let wallets = await getWallets()
17
+
18
+ // display wallets, have user pick one:
19
+
20
+ let wallet = wallets[0]
21
+
22
+ wallet.name // MetaMask
23
+ await wallet.connect() // 0x317D875cA3B9f8d14f960486C0d1D1913be74e90
24
+ ```
25
+
26
+ ## Demo
27
+
28
+ https://depayfi.github.io/web3-wallets/demo.html
29
+
30
+ ## Support
31
+
32
+ This library supports the following blockchains:
33
+
34
+ - [Ethereum](https://ethereum.org)
35
+ - [BNB Smart Chain](https://www.binance.org/smartChain)
36
+ - [Polygon](https://polygon.technology)
37
+ - [Solana](https://solana.com)
38
+ - [Fantom](https://fantom.foundation)
39
+ - [Arbitrum](https://arbitrum.io)
40
+ - [Avalanche](https://www.avax.network)
41
+ - [Gnosis](https://gnosis.io)
42
+ - [Optimism](https://www.optimism.io)
43
+ - [Base](https://base.org)
44
+ - [Worldchain](https://worldcoin.org/world-chain)
45
+
46
+ This library supports most crypto wallets:
47
+
48
+ See https://depay.com/wallets for more details
49
+
50
+ ## Platform specific packaging
51
+
52
+ In case you want to use and package only specific platforms, use platform-specific packages:
53
+
54
+ ### EVM specific packaging
55
+
56
+ ```javascript
57
+ import { getWallets } from '@depay/web3-wallets-evm'
58
+ ```
59
+
60
+ ### SOLANA specific packaging
61
+
62
+ ```javascript
63
+ import { getWallets } from '@depay/web3-wallets-svm'
64
+ ```
65
+
66
+ ## Functionalities
67
+
68
+ ### getWallets
69
+
70
+ `getWallets`: Returns an array of available/connectable wallets. Can wait up to 5 seconds because of checking existing WalletConnect connections.
71
+ Use `drip` to receive available wallets faster.
72
+
73
+ ```javascript
74
+ let availableWallets = await getWallets();
75
+ // [<Wallet name='MetaMask'>, <Wallet name='Phantom'>]
76
+ ```
77
+
78
+ ```javascript
79
+ let availableWallets = await getWallets();
80
+ // [] no wallets detected. (you can still try have user connec via WalletConnect or WalletLink)
81
+ ```
82
+
83
+ ```javascript
84
+ import { getWallets, wallets } from "@depay/web3-wallets"
85
+
86
+ let availableWallets = await getWallets()
87
+
88
+ let wallet
89
+ if(availableWallets.length == 1) {
90
+ wallet = availableWallets[0]
91
+ } else if(availableWallets.length > 1) {
92
+ wallet = availableWallets[parseInt(prompt('Which wallet do you want to connect?'), 10)]
93
+ } else {
94
+ // Let the user choose:
95
+ // you can still try to connect via wallets.WalletConnect.connect()
96
+ // or wallets.WalletLink.connect()
97
+ wallet = wallets.WalletLink
98
+ }
99
+ ```
100
+
101
+ #### drip
102
+
103
+ Pass a `drip` callback to `getWallets` to receive available wallet as soon as they are found, without waiting for all wallets to be checked:
104
+
105
+ ```javascript
106
+
107
+ getWallets({
108
+ drip: (wallet)=>{
109
+ setAvailableWallets(
110
+ availableWallets.concat([wallet])
111
+ )
112
+ }
113
+ })
114
+
115
+ ```
116
+
117
+ ### Name
118
+
119
+ `name:string`: Returns the name of the wallet.
120
+
121
+ ```javascript
122
+ wallet.name // 'MetaMask'
123
+ ```
124
+
125
+ ### Logo
126
+
127
+ `logo:string`: Returns the logo of the wallet as PNG base64-encoded.
128
+
129
+ ```javascript
130
+ wallet.logo // 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAclBMVEVHcEyBTif0snbypF3nhijulD7cq4Hv1b/wrW3dvqSieVvWyL2PXjvJuazndgD5hQB3PQ/PYQDkdADCrp3YwrPsegAVFRZyOg7ZawDzgQD/iQAeMklxNQMMDQ+3XwiLRw2hVAyCdmxPQz7dqoAyKiSgkoj9gMFYAAAADnRSTlMA8X2g78dnGzZPp57O1Hi2/psAAApFSURBVHja7Z2LVqM6FIZ7pUUrtbQRqEyLHX3/Vzy5soHcICSd41r5z3EcFUL+7m/vXKDOIioqKioqKioqKioqKioqKioqKioqKurXKnlJd4t/rB3uxGKuXur7Zr1f/EPt15t7/TK3ld2yKN5vaLv6R2HZrbbo9l4Uy7nXT+t33EyTZ5ttsls8Wbtku8nypihwH9LZZL1jFfcS5fmTEcNI5XlW3gvSg/plNlnvRASvDDf7NMQwUuR6GCvegeVuNllYDC+UkbafgNguwS6wEMWKqU49kPUu8MqwleCIUaRyEo7TndmYz5YgC/DCYogF8kKRYj4ygZUHtjhZPbywQiEmkBJYvfeunvohi+N1QhkXQSxdeFTKkBpg5YUtQZaMl3fEMFLUwRArP2wBWTJePhEDpDL6gUqOlS+2OFlqvLwhJp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vb9iNwNiPzxkdEHzs3nmKkpudyB2ozEZ6X6ibCUAWXo4Yb/kNeiAvvuXtoF4pVhkxXnDtvqmVjYarhNtnRiOAlboVk5F0xgZ2PtZJ2b8RaJ/3qxsxiBdf/wW4D1fveV77rF/XSBiyoADbQ9I5sK3DV0ngAw62BAQOTObsomRjneTSfeYrak4DNegqsIJjLT5AlKwgBbjbC+mO+fX0/edjoD/fpysezDVN4O+HKb68AI8LyfDXbG02H5KPD/ytzSYfNNkLSIBhnWlPG7E7KQc2/l5+iA/Zyc/lL7Mit2ARLb6hCnBLRjmwcbl8qY184R/93SiM2K7D7iKGKsBtP8q+DbORC42K3ECw4kuU5qPgKjs2mB5qIw/2U7AC54crvnx1ZbtEC0aecRt2I2AFzg82rANb9pDk3AboW23km/8YrOQ8ICGLryjAdif5wMbl/P2h1Pf50rOCaWQ+ghZfUYDtcAkbYORDI2EErJB4WjX77SNkcLeHZGjjAsOIPJBchlbK7Alk2djKCVTr1/NoI1/DI8+va/qrWQOTZSzAxAT7BbnpeWDl649GXwMb55Twu1pviJkQaypbAc7pb/lt/yWM9K1v5fH9pdT3o2/jLRWX2bPfTx6o+EIBlnnq/37f3du5a+Xr56zS5acTEfz1W7+NhAXG+7AuVldDF5QnSa+sq9BLtZXuAa/yK40DQ3Y4/Q7r7eqqx9Oa8aRzctb6kH78qrlg2kt/fHkvZNECDDwpCzokCpXNCPvLmymD95wyb8WXFWDOk/Ufudm98t6ajOAPJVY6yvwUX769te2lti0odsnh0FM2e00F6vFkD4pRcjisgfGT6j15Csqbt5c4rHav/sLxj/Vq9LH4Rdq9abH6PeHgQVHrV4UjKioqKioqKioqKioqKioqKioqKioqKirq/6z/AMhLOEXbTKvCAAAAAElFTkSuQmCC'
131
+ ```
132
+
133
+ ### Account
134
+
135
+ `async account():string`: Gets the currently connected and active account (without prompting a connect screen). Returns `undefined` if no account is connected.
136
+
137
+ ```javascript
138
+ await wallet.account() // '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B'
139
+ ```
140
+
141
+ ### Connect an account
142
+
143
+ `async connect():string`: Connects account. Potentially opens wallet connect screen. Provides connected account in async return. If wallet fails to connect, it returns `undefined`.
144
+
145
+ ```javascript
146
+ await wallet.connect() // '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B'
147
+ ```
148
+
149
+ ### Platform
150
+
151
+ `platform:string`: Platform of the identified wallet. If a wallet has multiplatform support (e.g. EVM + SVM), it will provide 1 wallet instance per platform (e.g. Phantom, Exodus, etc.)
152
+
153
+ ```javascript
154
+ wallet.platform // 'evm'
155
+ ```
156
+
157
+ ### Supported Blockchains
158
+
159
+ `blockchains:Array`: Array containing the names of supported blockchains
160
+
161
+ ```javascript
162
+ wallet.blockchains // ['ethereum', 'bsc', 'polygon']
163
+ ```
164
+
165
+ ### Check if wallet is connected to a specific blockchain
166
+
167
+ `async connectedTo(blockchain):Boolean`: Checks if wallet is connected to a specific blockchain.
168
+
169
+ ```javascript
170
+ await wallet.connectedTo('ethereum') // true
171
+ ```
172
+
173
+ If no param is given it well tell you to which blockchain the wallet is connected to:
174
+
175
+ ```javascript
176
+ await wallet.connectedTo() // 'bsc'
177
+ ```
178
+
179
+ can provide an array if connected to multiple blockchains:
180
+
181
+ ```javascript
182
+ await wallet.connectedTo() // ['ethereum', 'bsc']
183
+ ```
184
+
185
+ ### Receive wallet events
186
+
187
+ `on(string, function):undefined`: Register a callback function for given events.
188
+
189
+ ```javascript
190
+ wallet.on('account', (newAccount)=>{
191
+ doSomething(newAccount)
192
+ })
193
+ ```
194
+
195
+ #### Events
196
+
197
+ `on('account', (newAccount)=>{})`: Triggers when user changes the connected/active wallet account.
198
+
199
+ #### Deregister wallet events
200
+
201
+ `.on` returns a callback function that needs to be passed to `.off` if you want to deregister the event listener:
202
+
203
+ ```javascript
204
+ let callback = wallet.on('account', (newAccount)=>{
205
+ doSomething(newAccount)
206
+ })
207
+
208
+ //...
209
+
210
+ wallet.off('account', callback) // removes listener
211
+ ```
212
+
213
+ ### Switch blockchain/network
214
+
215
+ `async switchTo(blockchain)`: Changes wallet connection to a specific network (adds it to the wallet in case it's missing)
216
+
217
+ ```javascript
218
+ await wallet.switchTo('bsc')
219
+ ```
220
+
221
+ ### Transaction
222
+
223
+ ### Data Structure
224
+
225
+ `accepted: Function ()=>{}`: Callback that will be executed once the transaction has been accepted by the wallet but not sent to the network yet (e.g. relayer, World App). Has no transaction yet, as only sent can contain the transaction.
226
+
227
+ `api: Array`: Api of the contract (e.g. abi for Ethereum, Layout/Struct for Solana).
228
+
229
+ `blockchain: String`: Name of the blockchain e.g. 'ethereum'.
230
+
231
+ `failed: Function (transaction, error)=>{}`: Callback that will be executed once the transaction failed onchain (reverted).
232
+
233
+ `from: String`: Address of the transaction sender.
234
+
235
+ `id: String`: Identifier of the transaction.
236
+
237
+ `instructions: Array`: List of instructions (Solana).
238
+
239
+ `signers: Array`: List of signers (Solana).
240
+
241
+ `method: String`: Name of the contract method to be called (EVM).
242
+
243
+ `nonce: Integer`: Nonce (number only used once) of the transaction (EVM).
244
+
245
+ `params: Object or Array`: Parameters passed to the method (EVM).
246
+
247
+ `sent: Function (transaction)=>{}`: Callback that will be executed executed once the transaction has been sent to the network.
248
+
249
+ `succeeded: Function (transaction)=>{}`: Callback that will be executed once the transaction was successful and has been confirmed at least once by the network.
250
+
251
+ `to String`: Address of the contract to be transacted with (EVM).
252
+
253
+ `url String`: Url to open the transaction (e.g. in an explorer).
254
+
255
+ `value: Number or BigNumber as String`: Value of the transaction (amount of the native blockchain currency sent along with the transaction).
256
+
257
+ ### sendTransaction
258
+
259
+ #### EVM: sendTransaction
260
+
261
+ Available arguments for EVM blockchains:
262
+
263
+ `api: Array`: Api of the contract (e.g. abi for Ethereum).
264
+
265
+ `blockchain: String`: Name of the blockchain e.g. 'ethereum'.
266
+
267
+ `failed: Function (transaction, error)=>{}`: Callback to be executed if transaction failed (e.g. reverted).
268
+
269
+ `method: String`: Name of the contract method to be called.
270
+
271
+ `params: Object or Array`: Parameters passed to the method.
272
+
273
+ `sent: Function (transaction)=>{}`: Callback to be executed if transaction has been sent to the network.
274
+
275
+ `succeeded: Function (transaction)=>{}`: Callback to be executed if transaction was successful and has been confirmed once by the network.
276
+
277
+ `to String`: Address of the contract to be transacted with.
278
+
279
+ `value: Number or BigNumber as String`: Value of the transaction (amount of the native blockchain currency sent along with the transaction).
280
+
281
+
282
+ ##### EVM: Simple value transfer
283
+
284
+ e.g. sending 0.01 ETH on Ethereum:
285
+
286
+ ```javascript
287
+
288
+ let sentTransaction = await wallet.sendTransaction({
289
+ blockchain: 'ethereum',
290
+ to: '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92',
291
+ value: 0.01,
292
+ sent: function(transaction){},
293
+ succeeded: function(transaction){},
294
+ failed: function(transaction, error){}
295
+ })
296
+ ```
297
+
298
+ ##### EVM: Smart contract interaction
299
+
300
+ ```javascript
301
+ let sentTransaction = await wallet.sendTransaction({
302
+ blockchain: 'ethereum',
303
+ to: '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92',
304
+ api: [{"inputs":[{"internalType":"address","name":"_configuration","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"configuration","outputs":[{"internalType":"contract DePayRouterV1Configuration","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pluginAddress","type":"address"}],"name":"isApproved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"address[]","name":"plugins","type":"address[]"},{"internalType":"string[]","name":"data","type":"string[]"}],"name":"route","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}],
305
+ method: 'route',
306
+ params: {
307
+ path: ["0xb056c38f6b7Dc4064367403E26424CD2c60655e1","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb"],
308
+ amounts: ["11275067000000000000000","100000000000000000000", "1632063302"],
309
+ addresses: ["0x39794c3171d4D82eB9C6FBb764749Eb7ED92881d", "0x39794c3171d4D82eB9C6FBb764749Eb7ED92881d"],
310
+ plugins: ["0xe04b08Dfc6CaA0F4Ec523a3Ae283Ece7efE00019", "0x99F3F4685a7178F26EB4F4Ca8B75a1724F1577B9"],
311
+ data: []
312
+ },
313
+ value: "0",
314
+ sent: function(transaction){},
315
+ succeeded: function(transaction){},
316
+ failed: function(transaction, error){}
317
+ })
318
+ ```
319
+
320
+ #### Solana: sendTransaction
321
+
322
+ Available arguments for Solana blockchains:
323
+
324
+ `blockchain: String`: Name of the blockchain e.g. 'solana'.
325
+
326
+ `failed: Function (transaction, error)=>{}`: Callback to be executed if transaction failed (e.g. reverted).
327
+
328
+ `sent: Function (transaction)=>{}`: Callback to be executed if transaction has been sent to the network.
329
+
330
+ `succeeded: Function (transaction)=>{}`: Callback to be executed if transaction was successful and has been confirmed once by the network.
331
+
332
+ ##### Solana: Simple value transfer
333
+
334
+ e.g. send 0.01 SOL on Solana:
335
+
336
+ `to String`: Address of the receiver.
337
+
338
+ `value: Number or BigNumber as String`: Value of the transaction (only needed for simple SOL transfers).
339
+
340
+ ```javascript
341
+
342
+ let sentTransaction = await wallet.sendTransaction({
343
+ blockchain: 'solana',
344
+ to: '2UgCJaHU5y8NC4uWQcZYeV9a5RyYLF7iKYCybCsdFFD1',
345
+ value: 0.01,
346
+ sent: function(transaction){},
347
+ succeeded: function(transaction){},
348
+ failed: function(transaction, error){}
349
+ })
350
+ ```
351
+
352
+ ##### Solana: Sign and send instructions
353
+
354
+ `instructions Array`: A set of TransactionInstructions
355
+
356
+ e.g. Send 1 USDC:
357
+
358
+ ```javascript
359
+ import Token from '@depay/web3-tokens'
360
+
361
+ let sentTransaction = await wallet.sendTransaction({
362
+ blockchain: 'solana',
363
+ instructions: [
364
+ await Token.solana.createTransferInstructions({
365
+ token: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
366
+ amount: '1000000',
367
+ from: await wallet.account(),
368
+ to: '5AcFMJZkXo14r3Hj99iYd1HScPiM4hAcLZf552DfZkxas'
369
+ })
370
+ ],
371
+ sent: function(transaction){},
372
+ succeeded: function(transaction){},
373
+ failed: function(transaction, error){}
374
+ })
375
+ ```
376
+
377
+ ###### Solana: Instruction signers
378
+
379
+ If you need to sign an instruction (e.g. creating "throw away" accounts)
380
+
381
+ you can pass `signers` as part of the transaction passed to `sendTransaction`:
382
+
383
+ ```javascript
384
+ import { getProvider } from '@depay/web3-client'
385
+ import Token from '@depay/web3-tokens'
386
+ import { PublicKey, SystemProgram, Keypair } from '@depay/solana-web3.js'
387
+
388
+ const wallets = await getWallets()
389
+ const wallet = wallets[0]
390
+ const fromAddress = await wallet.account()
391
+ const provider = await getProvider('solana')
392
+ const keypair = Keypair.generate()
393
+ const account = keypair.publicKey.toString()
394
+ const rent = await provider.getMinimumBalanceForRentExemption(Token.solana.TOKEN_LAYOUT.span)
395
+
396
+ let instruction = SystemProgram.createAccount({
397
+ fromPubkey: new SolanaWeb3js.PublicKey(fromAddress),
398
+ newAccountPubkey: new SolanaWeb3js.PublicKey(wrappedAccount),
399
+ programId: new SolanaWeb3js.PublicKey(Web3Tokens.Token.solana.TOKEN_PROGRAM),
400
+ space: Web3Tokens.Token.solana.TOKEN_LAYOUT.span,
401
+ lamports: rent
402
+ })
403
+
404
+ let sentTransaction = await wallet.sendTransaction({
405
+ blockchain: 'solana',
406
+ instructions: [instruction],
407
+ signers: [keypair],
408
+ sent: function(transaction){},
409
+ succeeded: function(transaction){},
410
+ failed: function(transaction, error){}
411
+ })
412
+ ```
413
+
414
+ ###### Solana: Address Lookup Tables
415
+
416
+ If you need to pass address lookup tables in order to reduce transaction size,
417
+
418
+ you can pass `alts` as part of the transaction passed to `sendTransaction`:
419
+
420
+ ```javascript
421
+ import { getProvider } from '@depay/web3-client'
422
+ import Token from '@depay/web3-tokens'
423
+ import { PublicKey, SystemProgram, Keypair } from '@depay/solana-web3.js'
424
+
425
+ const wallets = await getWallets()
426
+ const wallet = wallets[0]
427
+ const fromAddress = await wallet.account()
428
+ const provider = await getProvider('solana')
429
+ const keypair = Keypair.generate()
430
+ const account = keypair.publicKey.toString()
431
+ const rent = await provider.getMinimumBalanceForRentExemption(Token.solana.TOKEN_LAYOUT.span)
432
+
433
+ let instruction = SystemProgram.createAccount({
434
+ fromPubkey: new SolanaWeb3js.PublicKey(fromAddress),
435
+ newAccountPubkey: new SolanaWeb3js.PublicKey(wrappedAccount),
436
+ programId: new SolanaWeb3js.PublicKey(Web3Tokens.Token.solana.TOKEN_PROGRAM),
437
+ space: Web3Tokens.Token.solana.TOKEN_LAYOUT.span,
438
+ lamports: rent
439
+ })
440
+
441
+ let sentTransaction = await wallet.sendTransaction({
442
+ blockchain: 'solana',
443
+ instructions: [instruction],
444
+ signers: [keypair],
445
+ alts: ['3sEm5YYxgLnP1Z11WXHSgScWqFMrATSNDgZcXAcB1w9A'],
446
+ sent: function(transaction){},
447
+ succeeded: function(transaction){},
448
+ failed: function(transaction, error){}
449
+ })
450
+ ```
451
+
452
+ #### value
453
+
454
+ If value is passed as a number it's gonna be converted into a big number applying the individual blockchain's default decimals:
455
+
456
+ ```javascript
457
+ let transaction = new Transaction({
458
+ ...,
459
+ value: 1
460
+ })
461
+
462
+ transaction.value // '1000000000000000000'
463
+ ```
464
+
465
+ If value is passed as a string or as a BigNumber, value is used just as provided:
466
+
467
+ ```javascript
468
+ let transaction = new Transaction({
469
+ ...,
470
+ value: '1000000000000000000'
471
+ })
472
+
473
+ transaction.value // '1000000000000000000'
474
+ ```
475
+
476
+ #### wrong network
477
+
478
+ `sendTransaction` rejects with:
479
+
480
+ ```javascript
481
+ { code: 'WRONG_NETWORK' }
482
+ ```
483
+
484
+ in case wallet is connected to the wrong network and network cant be switched automatically.
485
+
486
+ ### Get wallet transaction count
487
+
488
+ ```javascript
489
+ import { transactionCount } from '@depay/web3-wallets'
490
+
491
+ let count = await transactionCount({ blockchain: 'polygon', address: '0x8Ffdb4Ee24a625856c82db7FAAE5Bd8B3406eF86' })
492
+ ```
493
+
494
+ ### Sign messages
495
+
496
+ ```javascript
497
+ let signature = await wallet.sign("This is a message to be signed")
498
+ ```
499
+
500
+ ## Logos
501
+
502
+ ### Conversion
503
+
504
+ Use https://codebeautify.org
505
+
506
+ ## Development
507
+
508
+ ### Get started
509
+
510
+ ```
511
+ yarn install
512
+ yarn dev
513
+ ```
514
+
515
+ ### Release
516
+
517
+ ```
518
+ npm publish
519
+ ```