Leveraging Particle Connect within mobile applications built on Unity
wallet-adapter
, or private key imports). This creates a Web2-adjacent login experience while retaining unified compatibility with existing popular Web3 wallets.
Particle Connect has a dedicated Unity SDK for integration; the configuration process and examples of utilization are outlined below.
projectId
, clientKey
, and appId
.
These connect your Unity project directly with the Particle dashboard, enabling customization, analytics, tracking, etc.
.unitypackage
), then import this into your project.
Edit
-> Project Settings
-> Player Settings
-> iOS
).Other
, then scroll down to Configuration
.Supported URL schemes
section, and within the Element 0
field, paste in your projectId
with a prefix of pn
.
projectId
(from the Particle dashboard) is something like 63bfa427-cf5f-4742-9ff1-e8f5a1b9828f
, then the scheme URL, in this case, would be pn63bfa427-cf5f-4742-9ff1-e8f5a1b9828f
Remove other services, if needed
Within ParticleNetworkIOSBridge.cs
, you’ll have a number of services
included in the SDK:
- ParticleNetworkBase
- required universally.
- ParticleAuthCore
- required for Particle Auth Core.
- ParticleConnect
- required for Particle Connect.
ParticleWalletGUI
- usage of the Particle Wallet UI, contains all
services.- ParticleAA
- usage of the Particle AA, contains all services.
pod init
; this will generate a Podfile.
Open this Podfile, and insert the specific pods (services) you’d like to use within your project. In this case, ParticleConnect
and CommonConnect
will generally suffice, but additional services can be added if needed.
Additionally, you’ll need to paste in the code snippet below for installation handling:
pod install
and open your .xcworkspace
file, as shown below:
projectId
, clientKey
, and appId
previously retrieved. To do this, head to the root of your Xcode project and create a file called ParticleNetwork-Info.plist
. Within this file, paste the following text (then replace the placeholders):
Assets/Plugins/Android/launcherTemplate.gradle
within your project. Here, you’ll need to ensure you have the necessary dependencies included.
Specifically, you’ll need the following dependencies at a minimum:
network.particle:auth-service
if you’re planning on using Particle Auth directly.network.particle:connect
, required for Particle Connect.network.particle:unity-bridge
, required universally.network.particle:chains
, collection of chainInfo
objects.network.particle:connect-solana-adapter
, Solana-specific custom wallet adapter to be used within Particle Connect.network.particle:connect-phantom-adapter
, Wallet adapter for Phantom to be used within Particle Connect.network.particle:connect-evm-adapter
, EVM-specific custom wallet adapter to be used within Particle Connect.network.particle:connect-auth-adapter
, Particle Auth adapter for Particle Connect (social logins).network.particle:connect-wallet-connect-adapter
, WalletConnect adapter for Particle Connect.
The full list of network.particle
packages can be found here.projectId
, clientKey
, and appId
within gradleTemplate.properties
, which can be found at Assets/Plugins/Android/gradleTemplate.properties
.
ParticleNetwork
and ParticleConnectInteraction
(derived from Network.Particle.Scripts.Core
) before moving on. This is required for Particle Connect to function.
ParticleNetwork
can be initialized by simply calling Init
and passing in a chainInfo
object (*). ParticleConnectInteraction.Init
will require both a chainInfo
object and a DAppMetaData
parameter (in this example, represented as metadata
) containing a WalletConnect project ID retrieved from the WalletConnect dashboard, alongside the name of your project, the icon (preferably 512x512), the website URL, and a project description.
Additionally, with WalletConnect as the underlying infrastructure for Web3 wallets within Particle Connect, you’ll also have the opportunity to include configuration for multiple different chains on WalletConnect by calling ParticleConnectInteraction.SetWalletConnectV2SupportChainInfos
and passing in an array of chainInfo
objects.
An example of the above process can be found below.
Field | Type | Description |
---|---|---|
chainInfo | ChainInfo | The primary chain to be used within your application. This should be indicated by an overall blockchain, followed by a specific network. Within this example, it’s .Ethereum (alternatively it could be .EthereumSepolia , and so on.) |
dAppData | DAppMetadata | Metadata that describes your application and should be provided as an instance of DAppMetadata with the following parameters: walletConnectProjectId , the WalletConnect project ID retrieved from the WalletConnect dashboard, name , the name of your project. icon , a URL linking to the icon of your project; this should be 512x512, ideally. url , the URL of your project’s website. description , the description of your project, redirect , optional, a redirect universal link to you project, verifyUrl , optional. |
rpcUrl | RpcUrl? | Customize the RPC URL. |
env | Env | The specific environmennt to be used. This can be either .DEV , .STAGING , .PRODUCTION , this should be set to .PRODUCTION when released. |
ChainInfo
objects (chainInfos
in this example) and use it within ParticleConnectInteraction.SetWalletConnectV2SupportChainInfos
. E.g.:
.Init
and before a user is connected, you can call ParticleNetwork.SetChainInfo
, passing in the appropriate chainInfo
object for the desired chain.
If your application supports only EVM chains, ParticleNetwork.SetChainInfo
is sufficient and can be called anytime. However, if you support both EVM and Solana chains, use ParticleAuthCore.Instance.SwitchChain
when switching between EVM and Solana chains. For example:
Connect
drives connection with a wallet in the Particle Connect stack, (social login or otherwise.) This is done through ParticleConnect.Instance.Connect
, then passing in a relevant WalletType
object, derived from Network.Particle.Scripts.Model
WalletType
is an enum
containing the following choices:
AuthCore
, Particle Auth Core, an alternative to Particle Auth (Particle
).EvmPrivateKey
, custom EVM wallet imports/exports.SolanaPrivateKey
, custom Solana wallet imports/exports.MetaMask
.Rainbow
.Trust
.ImToken
.Bitget
.WalletConnect
.Zerion
.Math
.Inch1
.Zengo
.Alpha
.OKX
.TokenPocket
, not supported by iOS.Phantom
, intended for Solana.AuthCore
, you’ll also need to pass in a ConnectConfig
object containing:
Field | Type | Description |
---|---|---|
loginType | LoginType | The specific social login to be used. This can be either .EMAIL , .PHONE , .GOOGLE , .FACEBOOK , .APPLE , .TWITTER , .DISCORD , .GITHUB , .TWITCH , .MICROSOFT , .LINKEDIN or JWT . |
account | string? | (Optional) when type is set to either .email , .phone , or .jwt , 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 . The phone number must be in E.164 format. |
code | string? | (Optional) when type is set to either .email pr .phone , you can use the code parameter to pass the verification code. |
supportAuthTypes | List<SupportLoginType>? | The methods of authentication visible on the authentication popup UI. By default, this will be exclusive to the chosen social login method, although by passing in additional types, you can expand the UI to include the ability to login with those as an alternative to type. |
socialLoginPrompt | SocialLoginPrompt? | (Optional) either .None , .Consent , or .SelectAccount . |
loginPageConfig | LoginPageConfig? | (Optional) customize the UI page, includes project name, icon and description. |
ParticleConnect.Instance.Disconnect
, passing in the particular wallet type (WalletType
object) and associated address that you’d like to disconnect from your application, as is shown below.
IsConnected
, returning a Boolean indicating whether or not a user (or, in this case, an address and WalletType
) is currently connected to your application. This can be called through ParticleConnectInteraction.IsConnected
. E.g.:
ParticleConnect.Instance.SignAndSendTransaction
is the primary mechanism for EVM and Solana to send (or, in this case, suggest) transactions. Upon calling, the WalletType
(the adapter in question) will return a confirmation popup requesting a signature from the user before sending the transaction directly to the network. SignAndSendTransaction
takes three parameters:
WalletType
is the type of wallet being used.address
is the public address being used.transaction,
a stringified representation of a transaction object.ParticleConnect.Instance.SignTransaction
is a Solana-specific method for signing a transaction without pushing it to the network. This will behave similarly to SignAndSendTransaction
, although it will only function on either the Phantom
or SolanaPrivateKey
wallet types and will purely return a signature.
The plural of this method is ParticleConnect.Instance.SignAllTransactions
, which takes a list of transactions rather than just one to be prompted for signature.
ParticleConnect.Instance.SignMessage
, passing in the WalletType
, address
(publicAddress
in this example), and the message
in question. message
should be a general string to be signed. E.g.:
SignMessage
, 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 adapter.signTypedData
(equivalent to eth_signTypedData
, represented as either TypedDataV4
, TypedDataV2
, or TypedDataV1
). This takes the following parameters:
address
is the user address to target for signature initiation.data
, the typed data to be signed; see the Web (JavaScript/TypeScript) page for additional guidance.EvmPrivateKey
or SolanaPrivateKey
wallet types, you can import wallets through either a seed phrase or private key. These methods will associate an account instance derived from these keys, allowing utilization within your application.
These can be achieved through ImportWalletFromPrivateKey
for importing a private key, or ImportWalletFromMnemonic
for importing a mnemonic (seed phrase). These methods require the WalletType
(either EvmPrivateKey
or SolanaPrivateKey
) and the private key/seed phrase to be imported.
Additionally, you can export one of these wallets with ParticleConnect.Instance.ExportWalletPrivateKey
, passing in the address (of the EvmPrivateKey
or SolanaPrivateKey
imported/generated wallet) that you’d like to export.
ParticleConnect
includes ParticleAuthCore
. When logged in with a Particle account, you can access additional functions such as getUserInfo
, openAccountAndSecurity
, hasMasterPassword
, hasPaymentPassword
, and changeMasterPassword
. For more information, refer to the Auth SDK reference.