Skip to content

Commit 0c84993

Browse files
SunZhiCgitbook-bot
authored andcommitted
GITBOOK-1085: No subject
1 parent e178f32 commit 0c84993

File tree

1 file changed

+98
-84
lines changed

1 file changed

+98
-84
lines changed

developers/auth-service/sdks/flutter.md

Lines changed: 98 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ With Flutter:
1010
flutter pub add particle_auth
1111
```
1212

13-
click [here](https://github.com/Particle-Network/particle-flutter/tree/master/particle-auth) to get the demo source code 
13+
click [here](https://github.com/Particle-Network/particle-flutter/tree/master/particle-auth) to get the demo source code
1414

1515
### 2.Configure Android project
1616

@@ -169,7 +169,7 @@ override func application(_ app: UIApplication, open url: URL, options: [UIAppli
169169
{% endtab %}
170170
{% endtabs %}
171171

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`
173173

174174
Your scheme URL should be "pn" + your project app uuid.
175175

@@ -191,7 +191,7 @@ end
191191

192192
### Initialize the SDK
193193

194-
**Before using the SDK, you have to call init(Required)** 
194+
**Before using the SDK, you have to call init(Required)**
195195

196196
```dart
197197
ParticleAuth.init(Ethereum.mainnet(), env);
@@ -202,12 +202,12 @@ ParticleAuth.init(Ethereum.mainnet(), env);
202202
```dart
203203
List<SupportAuthType> supportAuthType = <SupportAuthType>[];
204204
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.
207207
final authorization = LoginAuthorization(messageHex, true);
208208
209209
//authorization is optional
210-
ParticleAuth.login(
210+
final userInfo = await ParticleAuth.login(
211211
LoginType.phone,
212212
"",
213213
supportAuthType,
@@ -216,20 +216,27 @@ ParticleAuth.login(
216216
);
217217
```
218218

219-
### Is Login
219+
### Is Login Async
220220

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.
222224

223225
```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+
}
225232
```
226233

227-
### Is Login Async
234+
### Is Login
228235

229-
Is user login, check from server, recommended.
236+
Is user login, check local data.
230237

231238
```dart
232-
String result = await ParticleAuth.isLoginAsync();
239+
bool result = await ParticleAuth.isLogin();
233240
```
234241

235242
### Logout
@@ -241,7 +248,7 @@ String result = await ParticleAuth.logout();
241248
### Fast logout
242249

243250
```dart
244-
String result = await ParticleAuth.fastLogoudar();
251+
String result = await ParticleAuth.fastLogout()
245252
```
246253

247254
### Get address
@@ -250,13 +257,19 @@ String result = await ParticleAuth.fastLogoudar();
250257
final address = await ParticleAuth.getAddress();
251258
```
252259

260+
### Get userInfo
261+
262+
```dart
263+
final userInfo = await ParticleAuth.getUserInfo();
264+
```
265+
253266
### Sign message
254267

255268
In EVM chain requires a hexadecimal string, in Solana chain requires a human readable string.
256269

257270
```dart
258271
final messageHex = "0x${StringUtils.toHexString("Hello Particle")}";
259-
String result = await ParticleAuth.signMessage(messageHex);
272+
String signature = await ParticleAuth.signMessage(messageHex);
260273
```
261274

262275
### Sign message unique
@@ -265,7 +278,7 @@ In EVM chain requires a hexadecimal string, not support Solana.
265278

266279
```dart
267280
final messageHex = "0x${StringUtils.toHexString("Hello Particle")}";
268-
String result = await ParticleAuth.signMessageUnique(messageHex);
281+
String signature = await ParticleAuth.signMessageUnique(messageHex);
269282
```
270283

271284
### Sign transaction
@@ -276,7 +289,7 @@ Please explore our GitHub. In the `example/transaction_mock.dart` file, you can
276289

277290
```dart
278291
final transaction = "Your transaction";
279-
String result = await ParticleAuth.signTransaction(trans);
292+
String pubAddress = await ParticleAuth.getAddress();
280293
```
281294

282295
### Sign all transactions
@@ -286,9 +299,9 @@ Only support Solana chain, in Solana chain requires a base58 string.
286299
Please explore our GitHub. In the `example/transaction_mock.dart` file, you can learn how to mock a test transaction.
287300

288301
```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);
292305
```
293306

294307
### Sign and send transaction
@@ -299,7 +312,7 @@ Please explore our GitHub. In the `example/transaction_mock.dart` file, you can
299312

300313
```dart
301314
final transaction = "Your transaction";
302-
String result = await ParticleAuth.signAndSendTransaction(trans);
315+
String signature = await ParticleAuth.signAndSendTransaction(transction);
303316
```
304317

305318
### Sign typed data
@@ -313,33 +326,28 @@ In EVM chain requires a hexadecimal string, not support Solana.
313326
```dart
314327
// your typed data is a json string
315328
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);
319331
```
320332

321-
### Set chain info async
333+
### Set chain info sync
322334

323335
```dart
324-
bool isSuccess = await ParticleAuth.setChainInfoAsync(EthereumChain.goerli());
336+
bool isSuccess = await ParticleAuth.setChainInfo(ChainInfo.PolygonMumbai);
325337
print("setChainInfoAsync: $isSuccess");
326338
```
327339

328-
### Set chain info sync
340+
### Set chain info async
329341

330342
```dart
331-
bool isSuccess = await ParticleAuth.setChainInfo(SolanaChain.devnet());
343+
bool isSuccess = await ParticleAuth.setChainInfoAsync(ChainInfo.SolanaDevnet);
332344
print("setChainInfoSync: $isSuccess");
333345
```
334346

335347
### Get chain info
336348

337349
```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();
343351
```
344352

345353
### Set security account config
@@ -360,8 +368,13 @@ ParticleAuth.setSecurityAccountConfig(config);
360368
If user is expired, should return error, If user is expired, should return error, otherwise return nothing.
361369

362370
```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+
}
365378
```
366379

367380
### Set iOS modal present style
@@ -372,7 +385,7 @@ ParticleAuth.setModalPresentStyle(IOSModalPresentStyle.fullScreen);
372385

373386
### Set iOS medium screen
374387

375-
Set iOS medium screen, true is medium screen, false is large screen, default value if false.&#x20;
388+
Set iOS medium screen, true is medium screen, false is large screen, default value if false.
376389

377390
Only support iOS 15 or higher.
378391

@@ -430,40 +443,15 @@ String webConfig =
430443
ParticleAuth.openWebWallet(webConfig);
431444
```
432445

433-
### Has master password, payment password, security account&#x20;
446+
### Has master password, payment password, security account
434447

435448
```dart
436449
// get hasMasterPassword, hasPaymentPassword and hasSecurityAccount from local user info.
437450
438451
final hasMasterPassword = await ParticleAuth.hasMasterPassword();
439452
final hasPaymentPassword = await ParticleAuth.hasPaymentPassword();
440453
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();
467455
```
468456

469457
## EVM Service
@@ -475,16 +463,18 @@ Get a write contract transaction
475463
```dart
476464
String publicAddress = "your public address";
477465
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"];
480471
481472
// abi json string, you can get it from your contract developer.
482473
// such as
483474
// [{\"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 = "";
487476
477+
final transaction = EvmService.writeContract(publicAddress, contractAddress, methodName, params, abiJsonString, true);
488478
```
489479

490480
### Read contract
@@ -494,13 +484,16 @@ Read conrtact data from blockchain
494484
```dart
495485
String publicAddress = "your public address";
496486
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];
499492
500493
// abi json string, you can get it from your contract developer.
501494
// such as
502495
// [{\"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 = "";
504497
505498
final result = await EvmService.readContract(publicAddress, contractAddress, methodName, parameters, abiJsonString);Cr
506499
```
@@ -514,12 +507,9 @@ final result = await EvmService.readContract(publicAddress, contractAddress, met
514507
String from = "your public address";
515508
String receiver = "receiver address"
516509
String contractAddress = "contract address"
517-
BigInt amount = "some amount";
510+
BigInt amount = BigInt.from(1000000);
518511
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);
523513
524514
// then create transaction
525515
final transaction = await EvmService.createTransaction(
@@ -532,23 +522,23 @@ final transaction = await EvmService.createTransaction(
532522
Return estimated gas
533523

534524
```dart
535-
final result = await EvmService.evmEstimateGas(from, to, value, data);
525+
final gasLimit = await EvmService.ethEstimateGas(from, to, value, data);
536526
```
537527

538528
### Get suggested gas fees
539529

540530
Return gas fee json object.
541531

542532
```dart
543-
final result = await EvmService.suggestedGasFees();
533+
final gasFees = await EvmService.suggestedGasFees();
544534
```
545535

546536
### Get tokens and NFTs
547537

548538
Return all tokens, NFTs and native amount at this address.
549539

550540
```dart
551-
final result = await EvmService.getTokensAndNFTs(publicAddress);
541+
final result = await EvmService.getTokensAndNFTs(address);
552542
```
553543

554544
### Get tokens
@@ -585,19 +575,43 @@ final result = await EvmService.getTransactionsByAddress(publicAddress);
585575

586576
### Get price
587577

588-
Return token price
578+
Return token price, if you want the native token price, use `native` as its address.
589579

590580
```dart
581+
List<String> currencies = <String>['usd'];
582+
List<String> tokenAddresses = <String>['native'];
583+
tokenAddresses.add('0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F');
584+
tokenAddresses.add('0x326C977E6efc84E512bB9C30f76E30c160eD06FB');
591585
final result = await EvmService.getPrice(tokenAddresses, currencies);
592586
```
593587

594588
### Get smart account
595589

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.
599591

600592
```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;
603607
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

Comments
 (0)