Skip to main content

Particle Connect for Android

Particle Connect is a custom, in-house connection modal designed to onboard users across different login verticals, including Web2 accounts via Particle Auth, various Web3 wallets via WalletConnect, Solana’s mobile wallet-adapter, and private key imports. This ensures universal accessibility within your application, bringing users, Web3-native or not, on-chain. Implementing Particle Connect as the primary connection mechanism within your Android application only takes a few steps, which are outlined below.

Repository

Before diving into the configuration and utilization process, you can review the Particle Connect Android SDK repository for an initial understanding of the underlying architecture, implementation flow and examples.
Particle Connect Wallet.
Using a private key or the mnemonic import/generate function is strongly discouraged. If you use it, you need to secure the data yourself, as Particle doesn’t have a relationship with the imported/generated mnemonic or private key.

Getting Started

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.

Dependencies

Installing and initializing Particle Connect is quite simple. In this case, it can be summarized in three steps. The first involves dependency management within your build.gradle file. Particle Connect requires numerous dependencies, the extent of which depends on the functions you intend to use within your application. To configure these dependencies, open your build.gradle file, and either paste the below code or conditionally define dependencies based upon which types of wallets you’d like to support:
build.gradle

Setting up the Particle dashboard

All implementations of Particle Connect (and Particle Auth) require three universal values: projectId, appId, and clientKey. These values tie a given implementation to the Particle dashboard, enabling configuration, analytics, tracking, etc.
Follow the quickstart tutorial to set up a project and find the required keys: Create a new project.

Configuration

Now that you’ve set your dependencies and retrieved your projectId (pn_project_id), clientKey (pn_project_client_key), and appId (pn_app_id), from the Particle dashboard, you’ll need to move on to configuring AndroidManifest.xml using the previously retrieved values to authenticate your implementation of Particle Connect. Open AndroidManifest.xml and either paste the below code or add a configuration that looks similar to the following:
XML

Initialization

Before proceeding to utilization and implementation, you must finish the setup process by initializing Particle Connect within Application#Create() (onCreate()). Until initialization occurs, Particle Connect will not work. This is the primary means of configuration. Initialization can be started through the init method on ParticleConnect (from com.particle.connect.ParticleConnect). init takes the following parameters:
Kotlin

Examples of utilization

Switch Chain

To switch the primary chain being used after initial configuration, you’ll need to retroactively call ParticleConnect.setChain, which takes one parameter, chain (should be a ChainInfo object imported from network.particle.chains.ChainInfo.Companion.{chain}). Upon calling this method, the chain will be switched for the current active session, as is shown below:
Kotlin

Get all Wallet Adapters

To retrieve a comprehensive list of current wallet adapters for either evm or solana, use the ParticleConnect.getAdapters method. Pass the desired chain type (evm or solana) as a parameter. For example:
Kotlin

Get all Connected Accounts

For a list of all currently connected accounts/addresses (via Particle Connect), you can call ParticleConnect.getAccounts while passing in the type of chain to retrieve active accounts for, either evm or solana. E.g.:
Kotlin

Connect Wallet V2

We recommend trying the Particle Connect Demo to easily customize and design your connect page. After customizing, you can copy the generated code from the Code Snippets section and paste it into the ConnectKit component to experience it directly in your app.

Dependencies

To include the Particle Connect Kit in your project, Ensure that the following dependency is present in your build.gradle file:
The ParticleConnectKit.connect function enables one-click login with a customizable UI. You can configure the login UI using the ConnectKitConfig parameters. ConnectKitConfig includes the following parameters: AdditionalLayoutOptions includes these parameters:

Connect Wallet V1

One of the key methods in the process is connect, which allows specific adapters to initiate a connection. This can be done by initializing the adapter in a variable, such as adapter. Depending on the adapter, invoking this method may trigger a modal to facilitate the connection. For EVMConnectAdapter and SolanaConnectAdapter, calling connect will generate a new account with a public and private key pair. For other adapters, the connection flow will vary based on the adapter used. For example: ConnectConfig ` There are 4 already implemented subclasses that can correspond to different connection scenarios
Kotlin

Disconnect Wallet

To programmatically force an account to disconnect from your application, you’ll need to call connectAdapter.disconnect, with connectAdapter referring to an instance of a given wallet adapter. This takes one parameter (other than the callback), address, which you can use to specify the address to disconnect. An example of this has been included below. E.g.:
Kotlin

Is Connected

In scenarios where you need to check if a specific account is connected, you can use the connectAdapter.connected method, which accepts the target address as a parameter. For example:
Kotlin

Import & Export Wallet

When using an instance of either EVMConnectAdapter or SolanaConnectAdapter within your connectAdapter setup, you can import a wallet using a private key or a mnemonic (seed phrase). To do this, use the connectAdapter.importWalletFromPrivateKey or connectAdapter.importWalletFromMnemonic methods. Both methods will return an account structure you can use within your application. Additionally, if you need to export a wallet, use the connectAdapter.exportWalletPrivateKey method. This requires passing the wallet address (either imported or generated via EVMConnectAdapter or SolanaConnectAdapter) that you wish to export.

This does not refer to importing/exporting wallets within Particle Auth; Particle Network’s MPC-TSS accounts do not support importing/exporting private keys.

This is specific to custom account connection with Particle Connect.

Kotlin

Sign and Send Transaction

To initiate a transaction for signature and ultimately settlement on-chain, you’ll need to use connectAdapter.signAndSendTransaction (for both EVM and Solana). This will return a popup to the adapter in question, prompting a signature from the end user. Once they confirm, the transaction will be immediately sent to the network. connectAdapter.signAndSendTransaction takes the following parameters:
  • address — The user address to target for initiating the transaction.
  • transaction — A stringified transaction object, including fields such as to, from, value, data, and others.
  • callback — A function to handle the transaction’s return response.
E.g.:
Kotlin

Sign Transaction

connectAdapter.signTransaction is a Solana-specific method for signing a transaction without pushing it to the network. Specifically, this method requires the following parameters: E.g.:
Kotlin

Sign Message

To sign a basic UTF-8 message (string), you can use connectAdapter.signMessage to prompt the user for a signature alongside the message in question. connectAdapter.signMessage takes the following parameters: E.g.:
Kotlin

Sign Typed Data

Alternatively, for EVM chains, you can request that a user signs typed (structured) data rather than purely a raw string. To do this, you can use connectAdapter.signTypedData (equivalent to eth_signTypedData). This takes the following parameters:
  • address — The user address to target for signature initiation.
  • data — The typed data to be signed. For more details, refer to the Web (JavaScript/TypeScript) documentation.
  • callback — A function to handle the response after the signature process.
E.g.:
Kotlin

(Optional) Custom WalletConnect Projcet ID

Kotlin

Custom WalletConnect Adapter

There may be cases where the existing selection of adapters doesn’t include a wallet you’d like to be featured within Particle Connect. Creating a custom adapter (using WalletConnect) is simple. Doing so will require a structure similar to the example below, in which a custom Coin98 adapter is made.
XML
Kotlin