Interacting with Particle Auth on Unity (Mobile) Using C#.
projectId
, clientKey
, and appId
.
These connect your Unity project with the Particle dashboard, enabling customization, analytics, tracking, etc.
particle-unity
GitHub repository, and download the latest release (.unitypackage
), then import it 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 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
, which will generate a Podfile.
Copy our example Podfile
You can copy our examole Podfile, it will always use the latest version.
ParticleConnect
and CommonConnect
will generally suffice, but additional services can be added if needed.
Additionally, you’ll need to paste the code snippet below for installation handling:
pod install
and open your .xcworkspace
file, such as is shown below:
projectId
, clientKey
, and appId
previously retrieved. To do this, head into the root of your Xcode project and create a file, ParticleNetwork-Info.plist
. Within this file, paste the following text (then replace the placeholders):
UnityManger.swift
, Unity-iPhone-Bridging-Header.h
and AppDelegate.swift
from under github /Assets/Plugins/iOS/.Swift , Copy files into the root of your Xcode project. Xcode will ask you if auto create Bridging file, click yes.
UnityManger.swift
, it has implemented methods defined in NativeCallProxy.h
.
NativeCallProxy.h
, in the file inspector, check public in Target Membership.
ParticleConnect
, you should add LSApplicationQueriesSchemes
to info.plist.
Assets/Plugins/Android/launcherTemplate.gradle
within your project. Here, you’ll need to ensure that you have the necessary dependencies.
Specifically, you’ll need the following dependencies at a minimum:
network.particle:auth-service
if you’re planning on using Particle Auth Directlynetwork.particle:unity-bridge
, required universallynetwork.particle
packages can be found here.projectId
, clientKey
, and appId
within gradleTemplate.properties
, found at Assets/Plugins/Android/gradleTemplate.properties
.
ParticleNetwork
. For the Unity SDK, this is handled by calling init
on ParticleNetwork
, which is derived from Network.Particle.Scripts.Core
and passing in information about the primary chain being used. This is generally pulled from a child of ChainInfo
.
ParticleAuthCore.prefab
is added to your main scene. This is required as Particle Auth Core will not function otherwise.
ParticleAuthCore.Instance.Connect
. Once this method is called, a corresponding login popup will be displayed requesting user authentication before returning to the application in a signed-in state.
ParticleAuthCore.Instance.Connect
takes the following parameters:
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. |
supportAuthTypeode | [SupportAuthType] | 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) Changes what the OAuth provider prompts a user to do; either .none , .consent , or .select_account . Only Google, Discord and Microsoft support it. |
loginPageConfig | LoginPageConfig? | (Optional) to customize the UI page, contains project name, icon and description. |
ParticleAuthCore.Instance.SendPhoneCode
or ParticleAuthCore.Instance.SendEmailCode
, connect with method ParticleAuthCore.Instance.ConnectWithCode
ParticleAuthCore.Instance.Disconnect
.
ParticleAuthCore.Instance.IsConnected
.
ParticleAuthCoreInteraction.GetUserInfo
to retrieve the userInfo.
ParticleAuthCoreInteraction.EvmGetAddress
or ParticleAuthCoreInteraction.SolanaGetAddress
can be called.
ParticleAuthCore.Instance.EvmPersonalSign
or ParticleAuthCore.Instance.SolanaPersonalSign
and passing in a standard string (no need for encoding on this method) with the message you’d like to be prompted for signature.
ParticleAuthCore.Instance.SolanaSignTransaction
and pass in a serialized (string) standard transaction object to be prompted for signature. This is a Solana-specific method.
ParticleAuthCore.Instance.SolanaSignAllTransactions
is another Solana-specific method that functions adjacent to the former but instead signs multiple (a list of) transactions represented as strings.
ParticleAuthCore.Instance.EvmSendTransaction
and ParticleAuthCore.Instance.SolanaSignAndSendTransaction
are the primary methods within the SDK for sending transactions as it immediately sends a given transaction after requesting signature (confirmation). This will also take a serialized (string) representation of a transaction,
ParticleAuthCore.Instance.EvmSignTypedData
is an EVM-specific method for signing structured (typed) data. For more information on signTypedData
, see the Web (JavaScript/TypeScript) page.
ParticleNetwork.SetChainInfo
, which simply takes a chainInfo
object parallel to the type of object passed into the original ParticleNetwork.Init
call.
ParticleAuthCore.Instance.OpenAccountAndSecurity
.
isConnected
function covered prior, there are various scenarios in which knowing whether or not a user has specific security settings enabled may be useful. In the case of the Particle Auth Flutter SDK, this can happen in one of two ways:
With the built-in ParticleAuthCoreInteraction.HasMasterPassword
, ParticleAuthCoreInteraction.HasPaymentPassword
, and ParticleAuthCore.Instance.ChangeMasterPassword
methods.
ParticleNetwork.SetSecurityAccountConfig
to update its value.EvmService
utilization examplesParticleAuthCore
for authentication and interaction with Particle’s Wallet-as-a-Service, the Unity mobile SDK also includes a class, EvmService
, for general interaction with EVM chains.
EvmService.WriteContract
allows you to execute a write contract call defined by a specific method and set of parameters. This requires a corresponding ABI, contract address, and requester public address.
Field | Type | Description |
---|---|---|
from | string | The user’s public address |
contractAddress | string | The contract address |
methodName | string | The method name that defined in the contract, add prefix custom_ , like custom_balanceOf , custom_mint |
parameters | List<object> | The method’s parameters |
abiJsonString | string? | The method’s abi json string |
gasFeeLevel | GasFeeLevel | (Optional) the gas fee level, High , Medium or Low , default is High |
EvmService.ReadContract
allows you to execute a read-only contract call defined by a specific method and set of parameters. This requires a corresponding ABI, contract address, and requester public address.
Field | Type | Description |
---|---|---|
from | string | The user’s public address |
contractAddress | string | The contract address |
methodName | string | The method name that defined in the contract, add prefix custom_ , like custom_balanceOf , custom_mint |
parameters | List<object> | The method’s parameters |
abiJsonString | string? | The method’s abi json string |
EvmService.CreateTransaction
facilitates the construction of a transaction object derived from the standard from
, to
(receiver
in this example), amount
(value
), and data
fields. This transaction, once constructed with EvmService.CreateTransaction
, can be passed for in-UI proposal with ParticleAuthCore.Instance.EvmSendTransaction
.
Field | Type | Description |
---|---|---|
from | string | The user’s public address. |
data | string | The transaction’s data. |
value | BigInteger | The native amount. |
to | String | The parameters of this method. |
gasFeeLevel | GasFeeLevel | (Optional) the gas fee level, High , Medium or Low , default is High . |
eth_estimateGas
). This is done through EvmService.EstimateGas
.
EvmService.SuggestedGasFees
.
EvmService
also extends to Data API methods such as GetTokensAndNFTs
, which returns a highly detailed JSON list of ERC20 tokens and ERC721 NFTs belonging to a specified address. This is accessible through EvmService.GetTokensAndNFTs
, passing in the public address to retrieve the tokens and NFTs of.
tokenAddresses
is an optional parameter, for get the specific tokens.
EvmService.GetTransactionsByAddress
enables the retrieval of a detailed JSON response containing a complete list of transactions involving a specified address.
EvmService.GetPrice
.
EvmService.Rpc
, as shown below.
SolanaService
utilization examplesParticleAuthCore
for authentication and interaction with Particle’s Wallet-as-a-Service, the Unity mobile SDK also includes a class, SolanaService
, for general interaction with Solana chains.
SolanaService
also extends to Data API methods such as GetTokensAndNFTs
, which returns a highly detailed JSON list of SPL tokens and NFTs belonging to a specified address. This is accessible through SolanaService.GetTokensAndNFTs
, passing in the public address to retrieve the tokens and NFTs of.
SolanaService.SerializeSOLTransaction
facilitates the construction of a SOL transaction object.
These transactions, once constructed , can be passed for in-UI proposal with ParticleAuthCore.Instance.SolanaSendTransaction
.
SolanaService.GetPrice
.
SolanaService.getTransactionsByAddress
.
SolanaService.GetTokenByTokenAddresses
.
EvmService
, standard RPC methods can be called through SolanaService.Rpc
.