2.1 open ${your flutter project} /android/app/build.gradle
2.1.1 add project config and update the minSdkVersion to 23
//Modify these configurations
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.particle_auth_test"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
//After modification:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.particle_auth_test"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 23 // required by particle sdk
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
//get from https://dashboard.particle.network/
manifestPlaceholders["PN_PROJECT_ID"] = "772f7499-1d2e-40f4-8e2c-7b6dd47db9de" //your project id
manifestPlaceholders["PN_PROJECT_CLIENT_KEY"] = "ctWeIc2UBA6sYTKJknT9cu9LBikF00fbk1vmQjsV" //your project client key
manifestPlaceholders["PN_APP_ID"] = "01a23ce8-d2e9-4b37-9eab-bf477279e53e" //your app id
}
2.1.2 update Java Version to 11 and add dataBinding config
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
Your scheme URL should be "pn" + your project app uuid.
For example, if your project app id is "63bfa427-cf5f-4742-9ff1-e8f5a1b9828f", your scheme URL is "pn63bfa427-cf5f-4742-9ff1-e8f5a1b9828f".
3.8 Edit Podfile, you should follow Podfile required to edit Podfile.
3.9 More important to note, our SDK is static xcframework, when introduced, you must specify the use of static libraries, use_frameworks! :linkage => :static
target 'Runner' do
use_frameworks! :linkage => :static
...other
end
Initialize the SDK
Before using the SDK, you have to call init(Required)
ParticleAuth.init(Ethereum.mainnet(), env);
Login
List<SupportAuthType> supportAuthType =<SupportAuthType>[];supportAuthType.add(SupportAuthType.all);//message:evm->hex sign message, solana is base58 string.//uniq:unique sign,only support evm.final authorization =LoginAuthorization(messageHex, true);//authorization is optionalfinal userInfo =awaitParticleAuth.login(LoginType.phone,"", supportAuthType, socialLoginPrompt, authorization);
Is Login Async
Is user login, check from server, recommended.
if you can get the userInfo, which means user is login, otherwise current user is invalid.
In EVM chain requires a hexadecimal string, not support Solana.
// your typed data is a json stringString typedDataHex ="0x${StringUtils.toHexString(typedData)}";final signature =awaitParticleAuth.signTypedData( typedDataHex, SignTypedDataVersion.v4);
final chainInfo =awaitParticleAuth.getChainInfo();
Set security account config
// set security account config, // the first parameter is promptSettingWhenSign, default value is 1.// the second parameter is promptMasterPasswordSettingWhenLogin, default value is 0.// 0 no prompt// 1 first time show prompt// 2 every time show prompt// 3 force show promptfinal config =SecurityAccountConfig(1, 2);ParticleAuth.setSecurityAccountConfig(config);
Open account and security page
If user is expired, should return error, If user is expired, should return error, otherwise return nothing.
try {String result =awaitParticleAuth.openAccountAndSecurity();print("openAccountAndSecurity: $result");} catch (error) {print("openAccountAndSecurity: $error");showToast("openAccountAndSecurity: $error");}
Has master password, payment password, security account
// get hasMasterPassword, hasPaymentPassword and hasSecurityAccount from local user info.final hasMasterPassword =awaitParticleAuth.hasMasterPassword();final hasPaymentPassword =awaitParticleAuth.hasPaymentPassword();final hasSecurityAccount =awaitParticleAuth.hasSecurityAccount();final securityAccount =awaitParticleAuth.getSecurityAccount();
EVM Service
Write Contract
Get a write contract transaction
String publicAddress ="your public address";String contractAddress ="your contract address";// this is your contract method name, like balanceOf, mint.String methodName ="mint"; // this is the method params, // all parameters should be convert to hex string.List<Object> params =<Object>["0x3"]; // abi json string, you can get it from your contract developer.// such as// [{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"quantity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]
const abiJsonString ="";final transaction =EvmService.writeContract(publicAddress, contractAddress, methodName, params, abiJsonString, true);
Read contract
Read conrtact data from blockchain
String publicAddress ="your public address";String contractAddress ="your contract address";// this is your contract method name, like balanceOf.String methodName ="balanceOf"; // this is the method params, // all parameters should be convert to hex string.List<Object> parameters =<Object>[publicAddress];// abi json string, you can get it from your contract developer.// such as// [{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"quantity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]
const abiJsonString ="";final result =awaitEvmService.readContract(publicAddress, contractAddress, methodName, parameters, abiJsonString);Cr
Create transaction
// if you want to send native, data should be 0x// we mock send some token, get data from EvmService.erc20TransferString from ="your public address";String receiver ="receiver address"String contractAddress ="contract address"BigInt amount =BigInt.from(1000000);String to = contractAddress;final data =awaitEvmService.erc20Transfer(contractAddress, receiver, amount);// then create transactionfinal transaction =awaitEvmService.createTransaction( from, data, BigInt.from(0), to, gasFeeLevel:GasFeeLevel.high);
Estimate gas
Return estimated gas
final gasLimit =awaitEvmService.ethEstimateGas(from, to, value, data);
Get suggested gas fees
Return gas fee json object.
final gasFees =awaitEvmService.suggestedGasFees();
Get tokens and NFTs
Return all tokens, NFTs and native amount at this address.
final result =awaitEvmService.getTokensAndNFTs(address);
Get tokens
Return all tokens and native amount at this address.
final result =awaitEvmService.getTokens(publicAddress);
Get NFTs
Return all NFTs at this address.
final result =awaitEvmService.getNFTs(publicAddress);
Get token by token addresses
Return the balance of the token specified below this address
final result =awaitEvmService.getTokenByTokenAddresses(publicAddress, tokenAddresses);
Get transactions by address
Return all transaction at this address
final result =awaitEvmService.getTransactionsByAddress(publicAddress);
Get price
Return token price, if you want the native token price, use native as its address.
List<String> currencies =<String>['usd'];List<String> tokenAddresses =<String>['native'];tokenAddresses.add('0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F');tokenAddresses.add('0x326C977E6efc84E512bB9C30f76E30c160eD06FB');final result =awaitEvmService.getPrice(tokenAddresses, currencies);
Get smart account
Make a SmartAccountConfig object, then call EvmService.getSmartAccount the result value should be a smart account.