Skip to main content

Particle Auth for Android

The Particle Auth Android SDK is the flagship mechanism for integrating Particle’s Wallet-as-a-Service within Android applications. This SDK is the sole facilitator of Android integration for most applications and is built for simplicity. As with the other Particle Auth SDKs, it requires only a few lines of code. Unlike the Unity SDK and Web SDK, the Android SDK differs in installation and configuration; these specific intricacies and setup processes are detailed below.

Getting Started

Using the Particle Auth Android SDK is straightforward but requires meeting a few minimum version prerequisites to ensure compatibility.

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.

Configuration

Before you begin using the Particle Auth Android SDK, you’ll need a few required universal values across all Particle Auth SDKs. These values are projectId, clientKey, and appId. All three can be retrieved by heading to the Particle dashboard.
Find a full rundown in the Dashboard Guide.

Installation

Once you’ve created a project and application on the Particle Dashboard, you can install and initialize ParticleNetwork. Start by declaring the Particle Auth SDK in your Gradle file.
Kotlin
For release updates, subscribe to the GitHub repository.
Additionally, you’ll need to declare specific configurations, such as inserting values above projectId, clientKey, and appId within the relevant AndroidManifest.xml file. An example of such a configuration is attached below. Placeholders such as pn_project_id will need to be filled in.
XML

Examples of utilization

Initialize the SDK

Upon application startup, ParticleNetwork must be initialized to function correctly. This can be done by calling the init method on ParticleNetwork and passing in the primary chain you intend to use within your application.
Kotlin

Switch Chain

To switch the chain after the initial configuration, use AuthCore.switchChain. This allows for asynchronous switching, just like the initial setup.
Kotlin

Login

AuthCore.connect triggers the standard login popup, which changes based on configurations like loginType (similar to the Web SDK’s preferredAuthType) and supportAuthTypeValues. This popup serves as the primary method for account creation and login for existing users. The AuthCore.login function accepts the following parameters:
You can use your existing user base or authentication method with Particle Auth through JWT. This way, your users can still log in with their current accounts. Check Custom Authentication (JWT) to learn how to configure it.
Kotlin

UserInfo and Address Retrieval (post-login)

After a successful login, you can retrieve detailed user information by calling the following methods.
Kotlin

Logout

AuthCore.disconnect logs the user out of their current session and returns them to their pre-login state.
Kotlin

Is User Logged In

AuthCore.isLogin returns a Boolean indicating whether the user is currently logged in with Particle.
Kotlin
If the user logs in on another device, causing their token to become invalid, you can use syncUserInfo to synchronize the information.

Signatures

Once ParticleNetwork has been initialized and a user has successfully logged in, signatures can be proposed for confirmation through a pop-up.

EVM

Signing Messages (EIP191)

To request an EIP191 signature from a user’s embedded wallet, you can use either the AuthCore.evm.personalSign or AuthCore.evm.personalSignUnique method. If you need the same message to return a unique signature each time, use the AuthCore.evm.personalSignUnique method. Otherwise, the AuthCore.evm.personalSignmethod is generally recommended.
signAndSendTransaction (Kotlin)

Signing Typed Data V4 (EIP712)

To request an EIP712 signature from a user’s embedded wallet, you can use either the AuthCore.evm.signTypedData or AuthCore.evm.signTypedDataUnique method. If you need the same message to return a unique signature each time, use the AuthCore.evm.signTypedDataUnique method. Otherwise, the AuthCore.evm.signTypedData method is generally recommended.
signAndSendTransaction (Kotlin)

Transaction

To send a transaction from a user’s embedded wallet, you can use AuthCore.evm.sendTransaction.
You can create an EVM transaction using the ParticleNetwork.evm.createTransaction() method.

Solana

Signing Messages

To request a signature from a user’s embedded wallet, use AuthCore.solana.signMessage.

Transaction

To send a transaction from a user’s embedded wallet, use AuthCore.solana.signAndSendTransaction.
To sign a transaction from a user’s embedded wallet, use “AuthCore.solana.signTransaction`.
To sign multiple transactions from a user’s embedded wallet, use AuthCore. Solana.signAllTransactions.

Open Account and Security

If you want to force the “Account and Security” options to open on-screen—where you can manage master passwords, payment passwords, additional accounts, and more—call AuthCore.openAccountAndSecurity.
Kotlin

Set Security Account Config

Within the security settings, specific popups can be configured to display during confirmation or when entering the wallet UI. These include promptSettingWhenSign for payment (signature) passwords and promptMasterPasswordSettingWhenLogin for a login-based master password. By default, promptSettingWhenSign is set to 1, prompting the user on the first signature for a given account. If set to 0, the prompt is never shown; if set to 2, it is shown for every signature confirmation. The same logic applies to promptMasterPasswordSettingWhenLogin, though it defaults to 0.
Kotlin

Master Password and Payment Password

Users can set a master password and payment password to protect their assets. To set or change the master password, call auth.changeMasterPassword. To set or change the payment password, call AuthCore.openAccountAndSecurity().

Language Setting

You can force a specific language within the UI using ParticleNetwork.setLanguage and retrieve the currently active language with ParticleNetwork.getAppliedLanguage. The default language is English.

Enable Blind Signing

Silently sign messages/transactions if the following conditions are met:
  1. Your account is connected via JWT.
  2. Your account does not have a payment password set.
  3. SecurityAccountConfig.promptSettingWhenSign is set to 0. You can update this value by calling ParticleNetwork.setSecurityAccountConfig.