Quickstart: Implementing Particle Auth within applications built with React Native

Particle Auth, the primary SDK driving standalone social logins, has native support for React Native (among numerous other platforms); integration only takes a few steps.

This document will go through the step-by-step process of configuring, initializing, and using Particle Auth with React Native.

For complete documentation covering the implementation of Particle Auth on React Native in more depth, head over to the React Native SDK reference.


1

Installing Particle Auth

Getting started, you’ll need to install @particle-network/rn-auth-core alongside @particle-network/rn-base.

To do this, execute the command(s) below.

Terminal
npm install @particle-network/rn-auth-core
npm install @particle-network/rn-base

// Or

yarn add @particle-network/rn-auth-core
yarn add @particle-network/rn-base
2

Configuring Particle Auth

Once installed, you’re ready to begin configuring Particle Auth.

To start, you’ll need to retrieve three key values from the Particle dashboard: your project ID, client key, and app ID. These are used to authenticate your instance of Particle Auth and connect your project to the dashboard;.

To retrieve these keys, follow the steps outlined below:

For more information on the Particle dashboard, take a look at the dashboard quickstart.


Android

If you’re planning on using Android for your React Native application, ensure you meet the following prerequisites (otherwise, expect compatibility issues):

Prerequisites

  • minSdkVersion 23 or higher.
  • compileSdkVersion, targetSdkVersion 34 or higher.
  • JavaVersion 17.
  • Jetpack (AndroidX).
  • Android Gradle Plugin Version: 8.5.1 or higher.
  • Gradle Version: 8.9 or higher. (before react-native:0.75.2, use 8.8)

Once you’ve made sure your project meets these requirements, you’ll need to move on and define the aforementioned configuration values (your project ID, client key, and app ID) within your build.grade file (which is generally found at ${project name}/android/app/build.gradle).

Specifically, within build.gradle, you’ll need to set four different values:

  1. dataBinding, this should be enabled with enabled = true.
  2. manifestPlaceholders["PN_PROJECT_ID"], the project ID previously retrieved from the Particle dashboard.
  3. manifestPlaceholders["PN_PROJECT_CLIENT_KEY"], the client key previously retrieved from the Particle dashboard.
  4. manifestPlaceholders["PN_APP_ID"], the app ID previously retrieved from the Particle dashboard.
build.gradle
android {
  ...
  defaultConfig {
      ......
      manifestPlaceholders["PN_PROJECT_ID"] = "Your project ID"
      manifestPlaceholders["PN_PROJECT_CLIENT_KEY"] = "Your client key"
      manifestPlaceholders["PN_APP_ID"] = "Your app ID"
  }

  dataBinding {
      enabled = true
  }

}

iOS

Alternatively, if you plan to use iOS for your React Native application, the underlying setup process differs slightly. Before diving in, you’ll need to ensure that your project meets the following requirements:

  • Xcode 15.0 or later.

  • iOS 14 or later.

With these requirements set, you’ll need to open an exported iOS project and navigate to ios/{project name}.xcworkspace.

1

Configuring ParticleNetwork-Info.plist

At the root of your Xcode project, create a new file, ParticleNetwork-Info.plist. Ensure this is marked under “Target Membership.”

From here, with a fresh ParticleNetwork-Info.plist file, go ahead and fill it in with the previously retrieved project keys (from the Particle dashboard):

ParticleNetwork-Info.plist
    <?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>
2

Configuring Info.plist: Face ID

Additionally, to enable Face ID (privacy setting) to your app, head over to (or create) the Info.plist file and include the following snippet:

Info.plist
<key>NSFaceIDUsageDescription</key>
  <string>We use Face ID for secure access to the app.</string>
3

Configuring your Podfile

Finally, you’ll need to edit your Podfile to align with the snippet below; this is required for all iOS projects that leverage Particle Auth Core.


// add ParticleAuthCore pods to your target
pod "Thresh", '2.0.2'
pod "ParticleMPCCore", '2.0.2'
pod "ParticleAuthCore", '2.0.2'
pod "AuthCoreAdapter", '2.0.2'

pod 'ParticleNetworkBase', '2.0.2'
pod 'ConnectCommon', '2.0.2'

pod 'SwiftyUserDefaults', :git ='https://github.com/SunZhiC/SwiftyUserDefaults.git', :branch ='master'
pod 'SkeletonView', :git ='https://github.com/SunZhiC/SkeletonView.git', :branch ='main'


post_install do |installer|
installer.pods_project.targets.each do |target|
  target.build_configurations.each do |config|
  config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
  end
 end

Specific note for using Expo.

If you’re working with Expo, your Podfile needs additional editing to ensure compatibility with Particle Auth Core, as below:

You can reference this Podfile.

post_install do |installer|
  installer.pods_project.targets.each do |target|
      if target.name == 'ParticleNetworkBase' or
         target.name == 'ParticleNetworkChains' or
         target.name == 'ParticleWalletAPI' or
         target.name == 'ParticleWalletGUI' or
         target.name == 'ParticleWalletConnect' or
         target.name == 'ParticleAA' or
         target.name == 'ParticleConnectKit' or
         target.name == 'ParticleConnect' or
         target.name == 'ConnectWalletConnectAdapter' or
         target.name == 'ConnectSolanaAdapter' or
         target.name == 'ConnectEVMAdapter' or
         target.name == 'ConnectPhantomAdapter' or
         target.name == 'ConnectCommon' or
         target.name == 'WalletConnectSwiftV2' or
         target.name == 'CryptoSwift' or
         target.name == 'SwiftyUserDefaults' or
         target.name == 'RxSwift' or
         target.name == 'RxCocoa' or
         target.name == 'RxRelay' or
         target.name == 'SwiftyJSON' or
         target.name == 'Base58.swift' or
         target.name == 'JXPagingView' or
         target.name == 'JXSegmentedView' or
         target.name == 'Starscream' or
         target.name == 'SwiftMessages' or
         target.name == 'SkeletonView' or
         target.name == 'GRDB.swift' or
         target.name == 'SnapKit' or
         target.name == 'BigInt' or
         target.name == 'Alamofire' or
         target.name == 'RxAlamofire' or
         target.name == 'Then' or
         target.name == 'Thresh' or
         target.name == 'ParticleMPCCore' or
         target.name == 'ParticleAuthCore' or
         target.name == 'AuthCoreAdapter'

         target.build_configurations.each do |config|
              config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
      end
    end
end

3

Initializing Particle Auth

Having now installed and configured Particle Auth based on the platform you’re using, you’ll need to initialize the SDK.

Particle Auth can be initialized by first setting your project ID and client key through defining ParticleInfo.projectId and ParticleInfo.clientKey.

After doing so, simply call the init method on particleBase. This takes the following parameters:

  • chainInfo, representing the primary chain you intend to use (for example, ChainInfo.Ethereum, chainInfo.Polygon).
  • env, affecting the information logged within your environment (Env.dev, Env.production, or Env.staging).

The snippet below is an example of this.

// Set your project info, retrieved from https://dashboard.particle.network.
ParticleInfo.projectId = ''; // your project id
ParticleInfo.clientKey = ''; // your client key

// Inititilze particleBase and particleAuthCore.
const chainInfo = Ethereum;
const env = Env.Dev;
particleBase.init(chainInfo, env);
particleAuthCore.init();
4

Facilitating social login

You’re ready to facilitate social login and interacting with the resulting account.

As shown below, you’ll need to call particleAuthCore.connect to initiate social login, passing in the specific login type you’d like the user to onboard through (.Google, .Twitter, .Discord, etc.) alongside, if applicable, the type of account prompt used by the OAuth provider (.SelectAccount, .Consent, .None).

When a user logs in for the first time, if there is no account, we will create one. Based on the current chainInfo, a new address will be generated. For example, if the current chain is EVM-compatible, only an EVM address will be generated; if it’s the Solana chain, only a Solana address will be generated. If you want to obtain both addresses, you can use ParticleAuthCore.switchChain to switch chains, and after waiting for 2 seconds, a new address for the selected chain will be generated for you.
const userInfo = await particleAuthCore.connect(LoginType.google, null, supportAuthTypes, SocialLoginPrompt.SelectAccount);

// Additionally, you can implement custom authentication through JWT.
// Learn more: https://developers.particle.network/guides/configuration/auth/jwt
const userInfo = await particleAuthCore.connect(LoginType.JWT, jwt);

Examples of Utilization

Retrieve User Information

With a user logged in, you’ll be able to retrieve information about their account (such as their address, or specific details regarding the social login mechanism they used) through methods such as evm.getAddress and particleAuthCore.getUserInfo (getUserInfo returns an object with numerous points of information; to learn more, head over to its API reference).

The following snippet is an example of retrieving a user’s address on both EVM and Solana alongside pulling their broader account information.

const evmAddress = await evm.getAddress();
const solanaAddress = await solana.getAddress();

const isSuccess = await particleAuthCore.switchChain(Solana);
const userInfo = await particleAuthCore.getUserInfo();

// If you're using account abstraction through @particle-network/rn-aa, you'll need to retrieve their address through the following:
const smartAccountParam = {
    name: AccountName.BICONOMY_V2().name,
    version: AccountName.BICONOMY_V2().version,
    ownerAddress: eoaAddress,
};
const result: SmartAccountInfo[] = await EvmService.getSmartAccount([smartAccountParam]);
const smartAccountAddress = result[0]?.smartAccountAddress;

Send a Transaction

Now, as a final example, you can send a transaction, such as burning 0.000000001 ETH.

To do this, you’ll need to construct a transaction with EvmService.createTransaction using standard parameters such as evmAddress (the sender), data, value, and receiverAddress,

Upon construction, the transaction can be sent through evm.sendTransaction; once the user signs/confirms, it’ll be pushed to the network; an example of this is shown below.

const evmAddress = await evm.getAddress();
const receiverAddress = "0x0000000000000000000000000000000000000000";
const value = BigNumber(0.000000001 * Math.pow(10, 18));
const data = "0x";

const transaction = EvmService.createTransaction(evmAddress, data, value, receiverAddress);
const txHash = await evm.sendTransaction(transaction);
Take a look at the complete demo project here.