React Native
Run this command:
npm install react-native-particle-auth
Make sure that your project meets the following requirements:
- Targets API Level 23 (Marshmallow) or higher
- Uses Android 6.0 or higher
- Java 11
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
}
}
- 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 Dashboard3.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:)
methodObjective-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
import * as particleAuth from "react-native-particle-auth";
Before using the SDK you have to call init(Required)
const chainInfo = ChainInfo.EthereumGoerli;
const env = Env.Production;
particleAuth.init(chainInfo, env);
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);
}
}
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);
}
const result = await particleAuth.logout();
if (result.status) {
console.log(result.data);
} else {
const error = result.data;
console.log(error);
}
logout silently
const result = await particleAuth.fastLogout();
if (result.status) {
console.log(result.data);
} else {
const error = result.data;
console.log(error);
}
const result = await particleAuth.isLogin();
jsconsole.log(result);
const address = await particleAuth.getAddress();
console.log(address)
const result = await particleAuth.getUserInfo();
const userInfo = JSON.parse(result);
console.log(userInfo);
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);
}
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);
}
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);
}
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);
}
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);
}
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);
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);
const result = await particleAuth.getChainInfo();
console.log(result);
const isDisplay = true;
particleAuth.setDisplayWallet(isDisplay);
particleAuth.openWebWallet();
const result = await particleAuth.openAccountAndSecurity();
if (result.status) {
const data = result.data;
console.log(data);
} else {
const error = result.data;
console.log(error);
}
setModalPresentStyle = async () => {
const style = iOSModalPresentStyle.FormSheet;
particleAuth.setModalPresentStyle(style)
}
// request iOS 15 or later
setMediumScreen = async () => {
const isMedium = true;
particleAuth.setMediumScreen(isMedium);
}
setLanguage = async () => {
const language = Language.JA;
particleAuth.setLanguage(language);
}
Last modified 8d ago