Links

React Native

1.Add the Auth Service SDK to Your React Native App

Run this command:
npm install react-native-particle-auth
click here to get the demo source code

2.Configure Android project

Prerequisites

Make sure that your project meets the following requirements:
  • Targets API Level 23 (Marshmallow) or higher
  • Uses Android 6.0 or higher
  • Java 11
Configure project information,Refer to here
android {
...
defaultConfig {
......
manifestPlaceholders["PN_PROJECT_ID"] = "your project id"
manifestPlaceholders["PN_PROJECT_CLIENT_KEY"] = "your project client key"
manifestPlaceholders["PN_APP_ID"] = "your app id"
}
//How you quote wallet sdk, you must set it
dataBinding {
enabled = true
}
}

3.Configure iOS project

Prerequisites

  • Install the following:
    • Xcode 14.1 or later.
  • Make sure that your project meets the following requirements:
    • Your project must target these platform versions or later:
      • iOS 13
3.1 After export iOS project, open your_project_name.xcworkspace under ios folder, here its name is ParticleAuthExample.xcworkspace.
3.2 Create a ParticleNetwork-Info.plist into the root of your Xcode project, and make sure the file is checked under Target Membership.
3.3 Copy the following text into this file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PROJECT_UUID</key>
<string>YOUR_PROJECT_UUID</string>
<key>PROJECT_CLIENT_KEY</key>
<string>YOUR_PROJECT_CLIENT_KEY</string>
<key>PROJECT_APP_UUID</key>
<string>YOUR_PROJECT_APP_UUID</string>
</dict>
</plist>
3.4 Replace YOUR_PROJECT_UUID, YOUR_PROJECT_CLIENT_KEY, and YOUR_PROJECT_APP_UUID with the new values created in your Dashboard
3.5. Import the ParticleAuthService module in your AppDelegate.swift file.
Objective-C
#import <react_native_particle_auth/react_native_particle_auth-Swift.h>
3.6. Add the scheme URL handle in your app's application(_:open:options:) method
Objective-C
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if ([ParticleAuthSchemeManager handleUrl:url] == YES) {
return YES;
} else {
// other methods
}
return YES;
}
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".
Config scheme url

Initialize the SDK

Usage

You can get the demo source code from here
import * as particleAuth from "react-native-particle-auth";

Initialize the SDK

Before using the SDK you have to call init(Required)
const chainInfo = ChainInfo.EthereumGoerli;
const env = Env.Production;
particleAuth.init(chainInfo, env);

Web3 provider

you can use our SDK as a web3 provider
const web3 = createWeb3('your project id', 'your client key');
web3_getAccounts = async () => {
const accounts = await web3.eth.getAccounts();
console.log('web3.eth.getAccounts', accounts);
}
web3_getBalance = async () => {
const accounts = await web3.eth.getAccounts();
const balance = await web3.eth.getBalance(accounts[0]);
console.log('web3.eth.getBalance', balance);
}
web3_getChainId = async () => {
const chainId = await web3.eth.getChainId();
console.log('web3.eth.getChainId', chainId);
}
web3_personalSign = async () => {
// for persion_sign
// don't use web3.eth.personal.sign
const result = await web3.currentProvider.request({
method: 'personal_sign',
params: ['hello world']
});
console.log('web3.eth.personal.sign', result);
}
web3_signTypedData_v1 = async () => {
try {
const accounts = await web3.eth.getAccounts();
const result = await web3.currentProvider.request({
method: 'eth_signTypedData_v1',
params: [[{ 'your typed data v1'}], accounts[0]]
});
console.log('web3 eth_signTypedData_v1', result);
} catch (error) {
console.log('web3 eth_signTypedData_v1', error);
}
}
web3_signTypedData_v3 = async () => {
try {
const accounts = await web3.eth.getAccounts();
const result = await web3.currentProvider.request({
method: 'eth_signTypedData_v3',
params: [accounts[0], { 'your typed data v3' }]
});
console.log('web3 eth_signTypedData_v3', result);
} catch (error) {
console.log('web3 eth_signTypedData_v3', error);
}
}
web3_signTypedData_v4 = async () => {
try {
const accounts = await web3.eth.getAccounts();
const result = await web3.currentProvider.request({
method: 'eth_signTypedData_v4',
params: [accounts[0], { 'your typed data v4 '}]
});
console.log('web3 eth_signTypedData_v4', result);
} catch (error) {
console.log('web3 eth_signTypedData_v4', error);
}
}
web3_sendTransaction = async () => {
try {
const accounts = await web3.eth.getAccounts();
const result = await web3.eth.sendTransaction(
{
from: accounts[0],
to: 'a receiver address or contract address',
value: '1000000',
data: '0x'
}
)
console.log('web3.eth.sendTransaction', result);
} catch (error) {
console.log('web3.eth.sendTransaction', error);
}
}
web3_wallet_switchEthereumChain = async () => {
try {
const result = await web3.currentProvider.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x61' }]
})
console.log('web3 wallet_switchEthereumChain', result);
} catch (error) {
console.log('web3 wallet_switchEthereumChain', error);
}
}

Login

const type = LoginType.Phone;
const supportAuthType = [SupportAuthType.All];
const result = await particleAuth.login(type, "", supportAuthType, undefined);
if (result.status) {
const userInfo = result.data;
console.log(userInfo);
} else {
const error = result.data;
console.log(error);
}

Logout

const result = await particleAuth.logout();
if (result.status) {
console.log(result.data);
} else {
const error = result.data;
console.log(error);
}

Fast logout

logout silently
const result = await particleAuth.fastLogout();
if (result.status) {
console.log(result.data);
} else {
const error = result.data;
console.log(error);
}

Is Login

const result = await particleAuth.isLogin();
jsconsole.log(result);

Get address

const address = await particleAuth.getAddress();
console.log(address)

Get user info

const result = await particleAuth.getUserInfo();
const userInfo = JSON.parse(result);
console.log(userInfo);

Sign message

const message = "Hello world!"
const result = await particleAuth.signMessage(message);
if (result.status) {
const signedMessage = result.data;
console.log(signedMessage);
} else {
const error = result.data;
console.log(error);
}

Sign transaction

const chainInfo = await particleAuth.getChainInfo();
if (chainInfo.chain_name.toLowerCase() != "solana") {
console.log("signTransaction only supports solana")
return
}
const sender = await particleAuth.getAddress();
console.log("sender: ", sender);
const transaction = await Helper.getSolanaTransaction(sender);
console.log("transaction:", transaction);
const result = await particleAuth.signTransaction(transaction);
if (result.status) {
const signedTransaction = result.data;
console.log(signedTransaction);
} else {
const error = result.data;
console.log(error);
}

Sign all transactions

const chainInfo = await particleAuth.getChainInfo();
if (chainInfo.chain_name.toLowerCase() != "solana") {
console.log("signAllTransactions only supports solana")
return
}
const sender = await particleAuth.getAddress();
const transaction1 = await Helper.getSolanaTransaction(sender);
const transaction2 = await Helper.getSplTokenTransaction(sender);
const transactions = [transaction1, transaction2];
const result = await particleAuth.signAllTransactions(transactions);
if (result.status) {
const signedTransactions = result.data;
console.log(signedTransactions);
} else {
const error = result.data;
console.log(error);
}

Sign and send transaction

const sender = await particleAuth.getAddress();
const chainInfo = await particleAuth.getChainInfo();
let transaction = "";
if (chainInfo.chain_name.toLowerCase() == "solana") {
transaction = await Helper.getSolanaTransaction(sender);
} else {
transaction = await Helper.getEthereumTransacion(sender);
}
console.log(transaction);
const result = await particleAuth.signAndSendTransaction(transaction);
if (result.status) {
const signature = result.data;
console.log(signature);
} else {
const error = result.data;
console.log(error);
}

Sign typed data

const chainInfo = await particleAuth.getChainInfo();
if (chainInfo.chain_name.toLowerCase() == "solana") {
console.log("signTypedData only supports evm")
return
}
const typedData = "[ { \"type\":\"string\", \"name\":\"Message\", \"value\":\"Hi, Alice!\" }, { \"type\":\"uint32\", \"name\":\"A nunmber\", \"value\":\"1337\" }]";
const version = "v1";
// particleAuth support typed data version v1, v3, v4
const result = await particleAuth.signTypedData(typedData, version);
if (result.status) {
const signature = result.data;
console.log(signature);
} else {
const error = result.data;
console.log(error);
}

Set chain info async

Login is required, if you want to switch to another chain, call this method after login.
const chainInfo = ChainInfo.SolanaDevnet;
const result = await particleAuth.setChainInfoAsync(chainInfo);
console.log(result);

Set chain info sync

if you want to switch to another chain, call this method before login.
const chainInfo = ChainInfo.EthereumGoerli;
const result = await particleAuth.setChainInfo(chainInfo);
console.log(result);

Get chain info

const result = await particleAuth.getChainInfo();
console.log(result);

Set display wallet

const isDisplay = true;
particleAuth.setDisplayWallet(isDisplay);

Open web wallet

particleAuth.openWebWallet();

Open account and security page

const result = await particleAuth.openAccountAndSecurity();
if (result.status) {
const data = result.data;
console.log(data);
} else {
const error = result.data;
console.log(error);
}

Set iOS modal present style and medium screen

setModalPresentStyle = async () => {
const style = iOSModalPresentStyle.FormSheet;
particleAuth.setModalPresentStyle(style)
}
// request iOS 15 or later
setMediumScreen = async () => {
const isMedium = true;
particleAuth.setMediumScreen(isMedium);
}

Set language

setLanguage = async () => {
const language = Language.JA;
particleAuth.setLanguage(language);
}
Last modified 8d ago