React Native Quickstart
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.
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.
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:
dataBinding
, this should be enabled withenabled = true
.manifestPlaceholders["PN_PROJECT_ID"]
, the project ID previously retrieved from the Particle dashboard.manifestPlaceholders["PN_PROJECT_CLIENT_KEY"]
, the client key previously retrieved from the Particle dashboard.manifestPlaceholders["PN_APP_ID"]
, the app ID previously retrieved from the Particle dashboard.
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
.
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):
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:
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.
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.
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
, orEnv.staging
).
The snippet below is an example of this.
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
).
ParticleAuthCore.switchChain
to switch chains, and after waiting for 2 seconds, a new address for the selected chain will be generated for you.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.
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.
Was this page helpful?