@@ -36,7 +36,7 @@ struct HDKey {
36
36
37
37
#### Create Account With Private Key
38
38
``` swift
39
- public func createWalletWithPrivateKey (withName : String ? ,
39
+ func createWalletWithPrivateKey (withName : String ? ,
40
40
password : String ,
41
41
completion : @escaping (KeyWalletModel? , Error ? ) -> Void )
42
42
{
@@ -115,7 +115,7 @@ func createHDWallet(withName name: String?,
115
115
116
116
#### Import Account With Private Key
117
117
``` swift
118
- public func addWalletWithPrivateKey (withName : String ? ,
118
+ func addWalletWithPrivateKey (withName : String ? ,
119
119
key : String ,
120
120
password : String ,
121
121
completion : @escaping (KeyWalletModel? , Error ? ) -> Void )
@@ -299,156 +299,6 @@ print("w3s token balance = " + String(bal))
299
299
300
300
### Prepare Transaction
301
301
302
- #### The class created to bound provider
303
-
304
- ``` swift
305
- /// A web3 instance bound to provider. All further functionality is provided under web.*. namespaces.
306
- public class web3 : Web3OptionsInheritable {
307
- public var provider : Web3Provider
308
- public var options : Web3Options = Web3Options.defaultOptions ()
309
- public var defaultBlock = " latest"
310
- public var requestDispatcher: JSONRPCrequestDispatcher
311
-
312
- /// Add a provider request to the dispatch queue.
313
- public func dispatch (_ request : JSONRPCrequest) -> Promise<JSONRPCresponse> {
314
- return self .requestDispatcher .addToQueue (request : request)
315
- }
316
-
317
- /// Raw initializer using a Web3Provider protocol object, dispatch queue and request dispatcher.
318
- public init (provider prov : Web3Provider, queue : OperationQueue? = nil , requestDispatcher : JSONRPCrequestDispatcher? = nil ) {
319
- provider = prov
320
- if requestDispatcher == nil {
321
- self .requestDispatcher = JSONRPCrequestDispatcher (provider : provider, queue : DispatchQueue.global (qos : .userInteractive ), policy : .Batch (32 ))
322
- } else {
323
- self .requestDispatcher = requestDispatcher!
324
- }
325
- }
326
-
327
- /// Keystore manager can be bound to Web3 instance. If some manager is bound all further account related functions, such
328
- /// as account listing, transaction signing, etc. are done locally using private keys and accounts found in a manager.
329
- public func addKeystoreManager (_ manager : KeystoreManager? ) {
330
- self .provider .attachedKeystoreManager = manager
331
- }
332
-
333
- var ethInstance: web3.Eth?
334
-
335
- /// Public web3.eth.* namespace.
336
- public var eth: web3.Eth {
337
- if (self .ethInstance != nil ) {
338
- return self .ethInstance !
339
- }
340
- self .ethInstance = web3.Eth (provider : self .provider , web3 : self )
341
- return self .ethInstance !
342
- }
343
-
344
- public class Eth :Web3OptionsInheritable {
345
- var provider:Web3Provider
346
- // weak var web3: web3?
347
- var web3: web3
348
- public var options: Web3Options {
349
- return self .web3 .options
350
- }
351
- public init (provider prov : Web3Provider, web3 web3instance : web3) {
352
- provider = prov
353
- web3 = web3instance
354
- }
355
- }
356
-
357
- var personalInstance: web3.Personal?
358
-
359
- /// Public web3.personal.* namespace.
360
- public var personal: web3.Personal {
361
- if (self .personalInstance != nil ) {
362
- return self .personalInstance !
363
- }
364
- self .personalInstance = web3.Personal (provider : self .provider , web3 : self )
365
- return self .personalInstance !
366
- }
367
-
368
- public class Personal :Web3OptionsInheritable {
369
- var provider:Web3Provider
370
- // weak var web3: web3?
371
- var web3: web3
372
- public var options: Web3Options {
373
- return self .web3 .options
374
- }
375
- public init (provider prov : Web3Provider, web3 web3instance : web3) {
376
- provider = prov
377
- web3 = web3instance
378
- }
379
- }
380
-
381
- var walletInstance: web3.Web3Wallet?
382
-
383
- /// Public web3.wallet.* namespace.
384
- public var wallet: web3.Web3Wallet {
385
- if (self .walletInstance != nil ) {
386
- return self .walletInstance !
387
- }
388
- self .walletInstance = web3.Web3Wallet (provider : self .provider , web3 : self )
389
- return self .walletInstance !
390
- }
391
-
392
- public class Web3Wallet {
393
- var provider:Web3Provider
394
- // weak var web3: web3?
395
- var web3: web3
396
- public init (provider prov : Web3Provider, web3 web3instance : web3) {
397
- provider = prov
398
- web3 = web3instance
399
- }
400
- }
401
-
402
- var browserFunctionsInstance: web3.BrowserFunctions?
403
-
404
- /// Public web3.browserFunctions.* namespace.
405
- public var browserFunctions: web3.BrowserFunctions {
406
- if (self .browserFunctionsInstance != nil ) {
407
- return self .browserFunctionsInstance !
408
- }
409
- self .browserFunctionsInstance = web3.BrowserFunctions (provider : self .provider , web3 : self )
410
- return self .browserFunctionsInstance !
411
- }
412
-
413
- public class BrowserFunctions :Web3OptionsInheritable {
414
- var provider:Web3Provider
415
- // weak var web3: web3?
416
- var web3: web3
417
- public var options: Web3Options {
418
- return self .web3 .options
419
- }
420
- public init (provider prov : Web3Provider, web3 web3instance : web3) {
421
- provider = prov
422
- web3 = web3instance
423
- }
424
- }
425
-
426
- var erc721Instance: web3.ERC721?
427
-
428
- /// Public web3.browserFunctions.* namespace.
429
- public var erc721: web3.ERC721 {
430
- if (self .erc721Instance != nil ) {
431
- return self .erc721Instance !
432
- }
433
- self .erc721Instance = web3.ERC721 (provider : self .provider , web3 : self )
434
- return self .erc721Instance !
435
- }
436
-
437
- public class ERC721 : Web3OptionsInheritable {
438
- var provider:Web3Provider
439
- // weak var web3: web3?
440
- var web3: web3
441
- public var options: Web3Options {
442
- return self .web3 .options
443
- }
444
- public init (provider prov : Web3Provider, web3 web3instance : web3) {
445
- provider = prov
446
- web3 = web3instance
447
- }
448
- }
449
- }
450
- ```
451
-
452
302
#### Getting Contract By Address
453
303
454
304
``` swift
@@ -487,8 +337,7 @@ func prepareTransactionForSendingEther(destinationAddressString: String,
487
337
return
488
338
}
489
339
490
-
491
- let web3 = web3swift.web3 (provider : InfuraProvider (CurrentNetwork.currentNetwork ?? Networks.Mainnet )! )
340
+ let web3 = web3swift.web3 (provider : InfuraProvider (Networks.Mainnet )! ) // or any other network
492
341
web3.addKeystoreManager (KeysService ().keystoreManager ())
493
342
494
343
let ethAddressFrom = EthereumAddress (selectedKey)
@@ -556,7 +405,7 @@ func prepareTransactionForSendingERC(destinationAddressString: String,
556
405
return
557
406
}
558
407
559
- let web3 = web3swift.web3 (provider : InfuraProvider (CurrentNetwork. currentNetwork ?? Networks.Mainnet )! )
408
+ let web3 = web3swift.web3 (provider : InfuraProvider (Networks.Mainnet )! ) // or any other network
560
409
web3.addKeystoreManager (KeysService ().keystoreManager ())
561
410
562
411
let contract = self .contract (for : token, web3 : web3)
@@ -631,7 +480,7 @@ func prepareTransactionToContract(data: [AnyObject],
631
480
let ethAddressFrom = EthereumAddress (address)
632
481
let ethContractAddress = EthereumAddress (contractAddress)!
633
482
634
- let web3 = CurrentWeb. currentWeb ?? Web3.InfuraMainnetWeb3 ()
483
+ let web3 = Web3.InfuraMainnetWeb3 () // or any other web
635
484
web3.addKeystoreManager (TransactionsService.keyservice .keystoreManager ())
636
485
var options = predefinedOptions ?? Web3Options.defaultOptions ()
637
486
options.from = ethAddressFrom
@@ -696,7 +545,7 @@ func sendToken(transaction: TransactionIntermediate,
696
545
697
546
#### Sending To Contract
698
547
``` swift
699
- public func sendToContract (transaction : TransactionIntermediate,
548
+ func sendToContract (transaction : TransactionIntermediate,
700
549
with password : String ? = " YOURPASSWORD" ,
701
550
options : Web3Options? = nil ,
702
551
completion : @escaping (Result<TransactionSendingResult>) -> Void ) {
@@ -726,5 +575,24 @@ public func sendToContract(transaction: TransactionIntermediate,
726
575
727
576
### Get Block number
728
577
578
+ ``` swift
579
+ func getBlockNumber (completion : @escaping (String ? ) -> Void ) {
580
+ DispatchQueue.global ().async {
581
+ let web3 = WalletWeb3Factory.web3 ()
582
+ let res = web3.eth .getBlockNumber ()
583
+ switch res {
584
+ case .failure (let error):
585
+ print (error)
586
+ DispatchQueue.main .async {
587
+ completion (nil )
588
+ }
589
+ case .success (let number):
590
+ DispatchQueue.main .async {
591
+ completion (number.description )
592
+ }
593
+ }
594
+ }
595
+ }
596
+ ```
729
597
730
598
### Get Block Gas Price
0 commit comments