Leveraging Particle Connect within Android applications.
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.
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:
projectId
, appId
, and clientKey
. These values tie a given implementation to the Particle dashboard, enabling configuration, analytics, tracking, etc.
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:
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:
Field | Type | Description |
---|---|---|
application | Application | Android applicaiton |
env | Env | DEV, STAGING, PRODUCTION. Different levels log different information |
chain | ChainInfo | The primary chain to be used within your application. ChainInfo can be set as a ChainInfo object imported from network.particle.chains.ChainInfo.Companion.{chain} . For example, ChainInfo.Ethereum or ChainInfo.Solana . |
dAppData | DAppMetadata | Metadata outlining the description of your application, used for WalletConnect . This should be set as an instance of DAppMetadata (imported from com.particle.base.model.DAppMetadata ) with the following parameters set:- name , the name of your project. - icon , a link containing the logo (icon) of your project; this should be 512x512, ideally.- url , the URL of your project’s website. - description , a short description of your project. |
createAdapters | (() -> List<IConnectAdapter> )? | You’ll need to define a list (listOf ) wallets (adapters) that you’d like to be provided as an option within your instance of Particle Connect (these can be imported from com.wallet.connect.adapter.{Adapter name} ). |
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:
evm
or solana
, use the ParticleConnect.getAdapters
method. Pass the desired chain type (evm
or solana
) as a parameter. For example:
ParticleConnect.getAccounts
while passing in the type of chain to retrieve active accounts for, either evm
or solana
. E.g.:
ConnectKit
component to experience it directly in your app.build.gradle
file:
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:
Field | Type | Description |
---|---|---|
connectOptions | List<ConnectOption> | connectOptions supports EMAIL , PHONE , SOCIAL , and WALLET ; the sort order is used for the Connect Kit login UI. |
socialProviders | List<EnableSocialProvider>? | socialProviders supports GOOGLE 、FACEBOOK 、APPLE 、TWITTER 、DISCORD 、GITHUB 、TWITCH 、MICROSOFT 、LINKEDIN . The sort order is used for the Connect Kit login UI. |
walletProviders | List<EnableWalletProvider>? | walletProviders supports MetaMask 、Rainbow 、Trust 、ImToken 、Bitget 、OKX 、Phantom 、WalletConnect . The sort order is used for the Connect Kit login UI. |
additionalLayoutOptions | AdditionalLayoutOptions | Layout options |
logo | String? | The top logo of the login UI can be customized by providing an image link or a base64-encoded image. If set to ‘null’, the default Particle logo will be used. |
AdditionalLayoutOptions
includes these parameters:
Field | Type | Description |
---|---|---|
isCollapseWalletList | Boolean | Determines if the wallet list should be collapsed. |
isSplitEmailAndSocial | Boolean | Specifies if email and social login options should be split. |
isSplitEmailAndPhone | Boolean | Indicates if email and phone login options should be split. |
isHideContinueButton | Boolean | Controls if the continue button is hidden. |
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:
Field | Type | Description |
---|---|---|
config | ConnectConifg? | The ConnectConfig will only be effective when adapter.name is MobileWCWalletName.AuthCore.name. You can construct a valid object using the subclass ParticleAuthCoreConfig. You can pass nullwhen adapter.walletType` is another value. |
ConnectConfig
` There are 4 already implemented subclasses that can correspond to different connection scenarios
Field | Type | Description |
---|---|---|
loginType | LoginType | The social login method in which users will be onboarded by default. This supports EMAIL , PHONE , TWITTER , GOOGLE , FACEBOOK , APPLE , DISCORD , GITHUB , TWITCH , MICROSOFT , LINKEDIN , JWT . |
account | String | The default is empty. You can use the account parameter to pass in an expected email, phone number, or JWT. This is optional for the former two but required for .jwt . If passing a phone number, it must be in E.164 format. |
supportLoginTypes | List<SupportLoginType> | Limits the login methods supported by the modal. The default setting supports all login types: EMAIL , PHONE , FACEBOOK , GOOGLE , APPLE , TWITTER , DISCORD , GITHUB , TWITCH , MICROSOFT , and LINKEDIN . You can also provide a specific subset of SupportLoginTypes if needed. |
prompt | LoginPrompt? | The prompt to be displayed following social login, such as a request to set a master password, payment password, etc. This is null by default. |
loginPageConfig | LoginPageConfig? | If you use Google to log in, you can control the Google account login prompt with this parameter: None , Consent , or SelectAccount . |
loginCallback | AuthCoreServiceCallback<UserInfo> | Callback that handles the login process’s success or failure. |
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.:
connectAdapter.connected
method, which accepts the target address as a parameter. For example:
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.
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.Field | Type | Description |
---|---|---|
publicAddress | String | For the connected public address, if adapter is AuthCoreAdapter , you can pass an empty string; for other wallet types, you need to pass a connected public address. |
transaction | String | EVM transaction, expressed as a hexadecimal string, or a Solana transaction, expressed as a base58 string. |
callback | TransactionCallback | A function to handle the transaction’s return response. |
connectAdapter.signTransaction
is a Solana-specific method for signing a transaction without pushing it to the network. Specifically, this method requires the following parameters:
Field | Type | Description |
---|---|---|
publicAddress | String | For the connected public address, if adapter is AuthCoreAdapter , you can pass an empty string; for other wallet types, you need to pass a connected public address. |
transaction | String | EVM transaction, expressed as a hexadecimal string, or a Solana transaction, expressed as a base58 string. |
callback | SignCallback | A function to handle the transaction’s return response. |
connectAdapter.signMessage
to prompt the user for a signature alongside the message in question. connectAdapter.signMessage
takes the following parameters:
Field | Type | Description |
---|---|---|
publicAddress | String | For the connected public address, if adapter is AuthCoreAdapter , you can pass an empty string; for other wallet types, you need to pass a connected public address. |
transaction | String | EVM transaction, expressed as a hexadecimal string, or a Solana transaction, expressed as a base58 string. |
callback | SignCallback | A function to handle the transaction’s return response. |
connectAdapter.signTypedData
(equivalent to eth_signTypedData
). This takes the following parameters:
Field | Type | Description |
---|---|---|
publicAddress | String | For the connected public address, if adapter is AuthCoreAdapter , you can pass an empty string; for other wallet types, you need to pass a connected public address. |
data | String | the typed data to be signed; see the Web (JavaScript/TypeScript) page for additional guidance. |
callback | SignCallback | A function to handle the transaction’s return response. |
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.