React Native Quickstart
Quickstart: Implementing Particle Connect within applications built with React Native
Particle Connect, the flagship SDK for facilitating onboarding through either social logins or standard wallet connection, has rich support for React Native, as will be covered here.
Specifically, this document will go through the step-by-step process of configuring, initializing, and using Particle Connect with React Native.
For complete documentation covering the implementation of Particle Connect on React Native in more depth, head over to the React Native SDK reference.
Installing Particle Connect
To begin, go ahead and add @particle-network/rn-connect
, @particle-network/rn-auth-core
, and @particle-network/rn-base
to your React Native application; this is a requirement before moving onto platform-specific configuration.
Configuring Particle Connect
Once the aforementioned libraries are installed, you’re ready to configure Particle Connect.
Most importantly within this process, you’ll need three key values from the Particle dashboard: your project ID, client key, and app ID. These are used to authenticate your instance of Particle Connect and connect your project to the dashboard; these are required to properly initialize the SDK.
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 that you meet the following 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 (project ID, client key, and app ID) within your build.grade
file (which is generally found at ${project name}/android/app/build.gradle
). These directly link your application’s instance of Particle Connect with the dashboard.
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, 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 find 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 aforementioned project keys (project ID, client key, and app ID):
Configuring AppDelegate.swift
Next, you’ll need to head over to your AppDelegate.swift
file to add an import of react_native_particle_connect
.
Additionally, within your application’s application
method (as shown below), you’ll need to include a handler condition derived from ParticleConnectSchemeManager handleUrl:url
. This should be as simple as a YES
(true) return upon a true value of ParticleConnectSchemeManager handleUrl:url
.
Setting your scheme URL
Additionally, you’ll need to configure your application’s scheme URL. To configure this, select your application from “TARGETS” under the “Info” section, then click ”+” to add a URL type.
For example, if your appId
is 63bfa427-cf5f-4742-9ff1-e8f5a1b9828f
, then the scheme URL would be pn63bfa427-cf5f-4742-9ff1-e8f5a1b9828f
—simply adding pn
to the beginning of the appId
.
Configuring Info.plist
Now, head over to your Info.plist
file and include the following snippet.
Configuring your Podfile
Finally, you’ll need to edit your Podfile to ensure particle_connect
is properly imported. Head over to the linked guide to complete this if you have not already.
Initializing Particle Connect
At this point, you’ve installed and configured Particle Connect; the only step remaining before the SDK can be used is initialization.
Particle Connect can be initialized by simply calling the init
method on particleConnect
. This takes the following parameters:
chainInfo
, representing the primary chain you intend to use (for example,ChainInfo.Ethereum
,chainInfo.Polygon
).metadata
, a collection of information about your project.env
, affecting the information logged within your environment (Env.dev
,Env.production
, orEnv.staging
).
An example of this has been included below.
Facilitating connection
At this point, you’re ready to facilitate connection through the Particle Connect modal (via either socials or standard wallets).
To do this, you’ll need to establish a config object specifying the:
- Onboarding mechanisms you’d like to support, through
connectOptions
(such asConnectOption.Email
,ConnectOption.Phone
,ConnectOption.Social
,ConnectOption.Wallet
). - Social login providers you’d like to support, through
socialProviders
(such asEnableSocialProvider.Google
,EnableSocialProvider.Apple
, and so on). - Wallets you’d like to be included as options within the modal, through
walletProviders
(such as EnableWallet.MetaMask, as shown below). - (Optionally), layout options altering the format of the connection modal through
additionalLayoutOptions
. - (Optionally), additional customizations, such as a custom icon, through
logo
.
Upon generating this config, you’ll be able to call particleConnect.connectWithConnectKitConfig
, initiating the resulting connection modal.
Examples of Utilization
Retrieving User Information
Upon wallet connection (or social login), you’ll be able to retrieve information about the resulting account.
Basic account information can be found through the result of particleConnect.connectWithConnectKitConfig
, in this case, that was saved to account
, which contains properties such as publicAddress
and walletType
.
To explicitly retrieve userInfo
(a collection of information regarding the login mechanism, attached addresses, and so on; more information can be found within its API reference), you’ll need to call particleAuthCore.getUserInfo
.
An example of both approaches can be found below.
Send a Transaction
To do this, you’ll need to construct a transaction with EvmService.createTransaction
using standard parameters such as evmAddress
(from, or the sender), data
, value
, and receiverAddress
(to, or the recipient),
To execute the resulting transaction, you’ll need to initialize an instance of the active connected wallet; an example of doing this has been included in the snippet below.
Finally, using this instance, the transaction can be executed through ParticleConnect.signAndSendTransaction
, taking the sender’s address alongside the previously constructed transaction object.
Open Wallet
If you installed @particle-network/rn-wallet
, you can open the (optional) embedded wallet interface at any time after a user connects, use particleWallet.setSupportChain
to set supported chains, then particleWallet.navigatorWallet
to open the interface.
particle_aa
SDK and refer to this documentation. Additionally, a demo repository can be found here. Was this page helpful?