@@ -10,7 +10,7 @@ With Flutter:
10
10
flutter pub add particle_auth
11
11
```
12
12
13
- click [ here] ( https://github.com/Particle-Network/particle-flutter/tree/master/particle-auth ) to get the demo source code&#x 20 ;
13
+ click [ here] ( https://github.com/Particle-Network/particle-flutter/tree/master/particle-auth ) to get the demo source code
14
14
15
15
### 2.Configure Android project
16
16
@@ -169,7 +169,7 @@ override func application(_ app: UIApplication, open url: URL, options: [UIAppli
169
169
{% endtab %}
170
170
{% endtabs %}
171
171
172
- 3.7. Configure your app scheme URL, select your app from ` TARGETS ` , under ` Info ` section, click + to add the ` URL types ` , and paste your scheme in ` URL Schemes `
172
+ 3.7. Configure your app scheme URL, select your app from ` TARGETS ` , under ` Info ` section, click + to add the ` URL types ` , and paste your scheme in ` URL Schemes `
173
173
174
174
Your scheme URL should be "pn" + your project app uuid.
175
175
191
191
192
192
### Initialize the SDK
193
193
194
- ** Before using the SDK, you have to call init(Required)** &#x 20 ;
194
+ ** Before using the SDK, you have to call init(Required)**
195
195
196
196
``` dart
197
197
ParticleAuth.init(Ethereum.mainnet(), env);
@@ -202,12 +202,12 @@ ParticleAuth.init(Ethereum.mainnet(), env);
202
202
``` dart
203
203
List<SupportAuthType> supportAuthType = <SupportAuthType>[];
204
204
supportAuthType.add(SupportAuthType.all);
205
- //message:evm->hex sign message . solana is base58
206
- //uniq:unique sign,only support evm
205
+ //message:evm->hex sign message, solana is base58 string.
206
+ //uniq:unique sign,only support evm.
207
207
final authorization = LoginAuthorization(messageHex, true);
208
208
209
209
//authorization is optional
210
- ParticleAuth.login(
210
+ final userInfo = await ParticleAuth.login(
211
211
LoginType.phone,
212
212
"",
213
213
supportAuthType,
@@ -216,20 +216,27 @@ ParticleAuth.login(
216
216
);
217
217
```
218
218
219
- ### Is Login
219
+ ### Is Login Async
220
220
221
- Is user login, check local data.
221
+ Is user login, check from server, recommended.
222
+
223
+ if you can get the userInfo, which means user is login, otherwise current user is invalid.
222
224
223
225
``` dart
224
- bool result = await ParticleAuth.isLogin();
226
+ try {
227
+ final userInfo = await ParticleAuth.isLoginAsync();
228
+ print("isLoginAsync: $userInfo");
229
+ } catch (error) {
230
+ print("isLoginAsync: $error");
231
+ }
225
232
```
226
233
227
- ### Is Login Async
234
+ ### Is Login
228
235
229
- Is user login, check from server, recommended .
236
+ Is user login, check local data .
230
237
231
238
``` dart
232
- String result = await ParticleAuth.isLoginAsync ();
239
+ bool result = await ParticleAuth.isLogin ();
233
240
```
234
241
235
242
### Logout
@@ -241,7 +248,7 @@ String result = await ParticleAuth.logout();
241
248
### Fast logout
242
249
243
250
``` dart
244
- String result = await ParticleAuth.fastLogoudar();
251
+ String result = await ParticleAuth.fastLogout()
245
252
```
246
253
247
254
### Get address
@@ -250,13 +257,19 @@ String result = await ParticleAuth.fastLogoudar();
250
257
final address = await ParticleAuth.getAddress();
251
258
```
252
259
260
+ ### Get userInfo
261
+
262
+ ``` dart
263
+ final userInfo = await ParticleAuth.getUserInfo();
264
+ ```
265
+
253
266
### Sign message
254
267
255
268
In EVM chain requires a hexadecimal string, in Solana chain requires a human readable string.
256
269
257
270
``` dart
258
271
final messageHex = "0x${StringUtils.toHexString("Hello Particle")}";
259
- String result = await ParticleAuth.signMessage(messageHex);
272
+ String signature = await ParticleAuth.signMessage(messageHex);
260
273
```
261
274
262
275
### Sign message unique
@@ -265,7 +278,7 @@ In EVM chain requires a hexadecimal string, not support Solana.
265
278
266
279
``` dart
267
280
final messageHex = "0x${StringUtils.toHexString("Hello Particle")}";
268
- String result = await ParticleAuth.signMessageUnique(messageHex);
281
+ String signature = await ParticleAuth.signMessageUnique(messageHex);
269
282
```
270
283
271
284
### Sign transaction
@@ -276,7 +289,7 @@ Please explore our GitHub. In the `example/transaction_mock.dart` file, you can
276
289
277
290
``` dart
278
291
final transaction = "Your transaction";
279
- String result = await ParticleAuth.signTransaction(trans );
292
+ String pubAddress = await ParticleAuth.getAddress( );
280
293
```
281
294
282
295
### Sign all transactions
@@ -286,9 +299,9 @@ Only support Solana chain, in Solana chain requires a base58 string.
286
299
Please explore our GitHub. In the ` example/transaction_mock.dart ` file, you can learn how to mock a test transaction.
287
300
288
301
``` dart
289
-
290
- final transactions = ["Your transaction 1", "Your transaction 2"];
291
- String result = await ParticleAuth.signAllTransactions(transactions);
302
+ List<String> transactions = <String>[];
303
+ List<String> signatures =
304
+ await ParticleAuth.signAllTransactions(transactions);
292
305
```
293
306
294
307
### Sign and send transaction
@@ -299,7 +312,7 @@ Please explore our GitHub. In the `example/transaction_mock.dart` file, you can
299
312
300
313
``` dart
301
314
final transaction = "Your transaction";
302
- String result = await ParticleAuth.signAndSendTransaction(trans );
315
+ String signature = await ParticleAuth.signAndSendTransaction(transction );
303
316
```
304
317
305
318
### Sign typed data
@@ -313,33 +326,28 @@ In EVM chain requires a hexadecimal string, not support Solana.
313
326
``` dart
314
327
// your typed data is a json string
315
328
String typedDataHex = "0x${StringUtils.toHexString(typedData)}";
316
- String result =
317
- await ParticleAuth.signTypedData(typedDataHex, SignTypedDataVersion.v4);
318
- debugPrint("signTypedData: $result");
329
+ final signature = await ParticleAuth.signTypedData(
330
+ typedDataHex, SignTypedDataVersion.v4);
319
331
```
320
332
321
- ### Set chain info async
333
+ ### Set chain info sync
322
334
323
335
``` dart
324
- bool isSuccess = await ParticleAuth.setChainInfoAsync(EthereumChain.goerli() );
336
+ bool isSuccess = await ParticleAuth.setChainInfo(ChainInfo.PolygonMumbai );
325
337
print("setChainInfoAsync: $isSuccess");
326
338
```
327
339
328
- ### Set chain info sync
340
+ ### Set chain info async
329
341
330
342
``` dart
331
- bool isSuccess = await ParticleAuth.setChainInfo(SolanaChain.devnet() );
343
+ bool isSuccess = await ParticleAuth.setChainInfoAsync(ChainInfo.SolanaDevnet );
332
344
print("setChainInfoSync: $isSuccess");
333
345
```
334
346
335
347
### Get chain info
336
348
337
349
``` dart
338
- String result = await ParticleAuth.getChainInfo();
339
- print(result);
340
- String chainName = jsonDecode(result)["chain_name"];
341
- int chainId = jsonDecode(result)["chain_id"];
342
- String chainIdName = jsonDecode(result)["chain_id_name"];
350
+ final chainInfo = await ParticleAuth.getChainInfo();
343
351
```
344
352
345
353
### Set security account config
@@ -360,8 +368,13 @@ ParticleAuth.setSecurityAccountConfig(config);
360
368
If user is expired, should return error, If user is expired, should return error, otherwise return nothing.
361
369
362
370
``` dart
363
- String result = await ParticleAuth.openAccountAndSecurity();
364
- print(result);
371
+ try {
372
+ String result = await ParticleAuth.openAccountAndSecurity();
373
+ print("openAccountAndSecurity: $result");
374
+ } catch (error) {
375
+ print("openAccountAndSecurity: $error");
376
+ showToast("openAccountAndSecurity: $error");
377
+ }
365
378
```
366
379
367
380
### Set iOS modal present style
@@ -372,7 +385,7 @@ ParticleAuth.setModalPresentStyle(IOSModalPresentStyle.fullScreen);
372
385
373
386
### Set iOS medium screen
374
387
375
- Set iOS medium screen, true is medium screen, false is large screen, default value if false.&#x 20 ;
388
+ Set iOS medium screen, true is medium screen, false is large screen, default value if false.
376
389
377
390
Only support iOS 15 or higher.
378
391
@@ -430,40 +443,15 @@ String webConfig =
430
443
ParticleAuth.openWebWallet(webConfig);
431
444
```
432
445
433
- ### Has master password, payment password, security account&#x 20 ;
446
+ ### Has master password, payment password, security account
434
447
435
448
``` dart
436
449
// get hasMasterPassword, hasPaymentPassword and hasSecurityAccount from local user info.
437
450
438
451
final hasMasterPassword = await ParticleAuth.hasMasterPassword();
439
452
final hasPaymentPassword = await ParticleAuth.hasPaymentPassword();
440
453
final hasSecurityAccount = await ParticleAuth.hasSecurityAccount();
441
-
442
- // get from remote server
443
- static void getSecurityAccount() async {
444
- final result = await ParticleAuth.getSecurityAccount();
445
- if (result == null) return;
446
-
447
- if (jsonDecode(result)["status"] == true ||
448
- jsonDecode(result)["status"] == 1) {
449
- final securityAccount = jsonDecode(result)["data"];
450
- bool hasMasterPassword = securityAccount["has_set_master_password"];
451
- bool hasPaymentPassword = securityAccount["has_set_payment_password"];
452
- final email = securityAccount["email"];
453
- final phone = securityAccount["phone"];
454
-
455
- bool hasSecurityAccount = (email != null && !email.isEmpty) ||
456
- (phone != null && !phone.isEmpty);
457
- print(
458
- "hasMasterPassword: $hasMasterPassword, hasPaymentPassword: $hasPaymentPassword, hasSecurityAccount: $hasSecurityAccount");
459
- showToast(
460
- "hasMasterPassword: $hasMasterPassword, hasPaymentPassword: $hasPaymentPassword, hasSecurityAccount: $hasSecurityAccount");
461
- } else {
462
- final error = RpcError.fromJson(jsonDecode(result)["data"]);
463
- print(error);
464
- showToast("getSecurityAccount: $error");
465
- }
466
- }
454
+ final securityAccount = await ParticleAuth.getSecurityAccount();
467
455
```
468
456
469
457
## EVM Service
@@ -475,16 +463,18 @@ Get a write contract transaction
475
463
``` dart
476
464
String publicAddress = "your public address";
477
465
String contractAddress = "your contract address";
478
- String methodName = "mint"; // this is your contract method name, like balanceOf, mint.
479
- List<Object> params = <Object>["1"]; // this is the method params.
466
+ // this is your contract method name, like balanceOf, mint.
467
+ String methodName = "mint";
468
+ // this is the method params,
469
+ // all parameters should be convert to hex string.
470
+ List<Object> params = <Object>["0x3"];
480
471
481
472
// abi json string, you can get it from your contract developer.
482
473
// such as
483
474
// [{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"quantity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]
484
- const abiJsonString = null;
485
-
486
- final result = EvmService.writeContract(publicAddress, contractAddress, methodName, params, abiJsonString, true);
475
+ const abiJsonString = "";
487
476
477
+ final transaction = EvmService.writeContract(publicAddress, contractAddress, methodName, params, abiJsonString, true);
488
478
```
489
479
490
480
### Read contract
@@ -494,13 +484,16 @@ Read conrtact data from blockchain
494
484
``` dart
495
485
String publicAddress = "your public address";
496
486
String contractAddress = "your contract address";
497
- String methodName ="mint"; // this is your contract method name, like balanceOf, mint.
498
- List<Object> parameters = <Object>["1"]; // this is the method params.
487
+ // this is your contract method name, like balanceOf.
488
+ String methodName ="balanceOf";
489
+ // this is the method params,
490
+ // all parameters should be convert to hex string.
491
+ List<Object> parameters = <Object>[publicAddress];
499
492
500
493
// abi json string, you can get it from your contract developer.
501
494
// such as
502
495
// [{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"quantity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]
503
- const abiJsonString = null ;
496
+ const abiJsonString = "" ;
504
497
505
498
final result = await EvmService.readContract(publicAddress, contractAddress, methodName, parameters, abiJsonString);Cr
506
499
```
@@ -514,12 +507,9 @@ final result = await EvmService.readContract(publicAddress, contractAddress, met
514
507
String from = "your public address";
515
508
String receiver = "receiver address"
516
509
String contractAddress = "contract address"
517
- BigInt amount = "some amount" ;
510
+ BigInt amount = BigInt.from(1000000) ;
518
511
String to = contractAddress;
519
- final erc20Resp =
520
- await EvmService.erc20Transfer(contractAddress, receiver, amount);
521
- // get field data
522
- final data = jsonDecode(erc20Resp)["result"];
512
+ final data = await EvmService.erc20Transfer(contractAddress, receiver, amount);
523
513
524
514
// then create transaction
525
515
final transaction = await EvmService.createTransaction(
@@ -532,23 +522,23 @@ final transaction = await EvmService.createTransaction(
532
522
Return estimated gas
533
523
534
524
``` dart
535
- final result = await EvmService.evmEstimateGas (from, to, value, data);
525
+ final gasLimit = await EvmService.ethEstimateGas (from, to, value, data);
536
526
```
537
527
538
528
### Get suggested gas fees
539
529
540
530
Return gas fee json object.
541
531
542
532
``` dart
543
- final result = await EvmService.suggestedGasFees();
533
+ final gasFees = await EvmService.suggestedGasFees();
544
534
```
545
535
546
536
### Get tokens and NFTs
547
537
548
538
Return all tokens, NFTs and native amount at this address.
549
539
550
540
``` dart
551
- final result = await EvmService.getTokensAndNFTs(publicAddress );
541
+ final result = await EvmService.getTokensAndNFTs(address );
552
542
```
553
543
554
544
### Get tokens
@@ -585,19 +575,43 @@ final result = await EvmService.getTransactionsByAddress(publicAddress);
585
575
586
576
### Get price
587
577
588
- Return token price
578
+ Return token price, if you want the native token price, use ` native ` as its address.
589
579
590
580
``` dart
581
+ List<String> currencies = <String>['usd'];
582
+ List<String> tokenAddresses = <String>['native'];
583
+ tokenAddresses.add('0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F');
584
+ tokenAddresses.add('0x326C977E6efc84E512bB9C30f76E30c160eD06FB');
591
585
final result = await EvmService.getPrice(tokenAddresses, currencies);
592
586
```
593
587
594
588
### Get smart account
595
589
596
- Require add particle\_ biconomy and enable Biconomy.
597
-
598
- Return smart account json object
590
+ Make a ` SmartAccountConfig ` object, then call ` EvmService.getSmartAccount ` the result value should be a smart account.
599
591
600
592
``` dart
601
- final result = await EvmService.getSmartAccount(eoaAddresses, version);
602
- ```
593
+ try {
594
+ final eoaAddress = await ParticleAuth.getAddress();
595
+ SmartAccountConfig config = SmartAccountConfig(
596
+ AccountName.BICONOMY, VersionNumber.V1_0_0(), eoaAddress);
597
+ List<dynamic> response =
598
+ await EvmService.getSmartAccount(<SmartAccountConfig>[config]);
599
+
600
+ var smartAccountJson = response.firstOrNull;
601
+ if (smartAccountJson != null) {
602
+ print(smartAccountJson);
603
+ final smartAccount = smartAccountJson as Map<String, dynamic>;
604
+
605
+ final smartAccountAddress =
606
+ smartAccount["smartAccountAddress"] as String;
603
607
608
+ print("getSmartAccount: $smartAccountAddress");
609
+ showToast("getSmartAccount: $smartAccountAddress");
610
+ } else {
611
+ print('List is empty');
612
+ }
613
+ } catch (error) {
614
+ print("getSmartAccount: $error");
615
+ showToast("getSmartAccount: $error");
616
+ }
617
+ ```
0 commit comments