Before using, please review the prerequisites, All unity SDKs are open source, click here to view
- Before using the sdk you have to call init(Required)
ParticleNetwork.Init(_chainInfo);
ParticleAuthCoreInteraction.Init();
- Drag prefab to your scene
Drag the ParticleAuthCore.prefab to your first scene(Required)
If loginType is email or phone, you can pass email address or phone number to account
.
If loginType is JWT, you must pass JWT token to account
.
SocialLoginPrompt: optional, only google, discord and microsoft support it.
If loginType is email or phone, below parameter is optional, other wise, they are useless.
The supportAuthTypes
controls which types of social login buttons are displayed at the bottom of the login page.
The loginPageConfig
controls the title, description, and image displayed on the login page.
public async void Connect()
{
try
{
List<SupportLoginType> allSupportLoginTypes = new List<SupportLoginType>(Enum.GetValues(typeof(SupportLoginType)) as SupportLoginType[]);
var nativeResultData =
await ParticleAuthCore.Instance.Connect(LoginType.GOOGLE, null, allSupportLoginTypes, SocialLoginPrompt.SelectAccount,
new LoginPageConfig("Particle Unity Example", "Welcome to login", "https://connect.particle.network/icons/512.png"));
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
{% hint style="info" %} Connect with JWT
var jwt = "your jwt";
var nativeResultData = await ParticleAuthCore.Instance.ConnectJWT(jwt);
{% endhint %}
Send verification code
var nativeResultData = await ParticleAuthCore.Instance.SendEmailCode(email);
Connect with email or phone and verification code
var nativeResultData = await ParticleAuthCore.Instance.ConnectWithCode(null,email, code);
public async void Disconnect()
{
try
{
var nativeResultData = await ParticleAuthCore.Instance.Disconnect();
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public async void IsConnected()
{
try
{
var nativeResultData = await ParticleAuthCore.Instance.IsConnected();
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public async void SwitchChain()
{
try
{
var nativeResultData = await ParticleAuthCore.Instance.SwitchChain(this._chainInfo);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public async void ChangeMasterPassword()
{
try
{
var nativeResultData =
await ParticleAuthCore.Instance.ChangeMasterPassword();
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public void HasPaymentPassword()
{
var result = ParticleAuthCoreInteraction.HasPaymentPassword();
Debug.Log($"has master password {result}");
}
public void HasMasterPassword()
{
var result = ParticleAuthCoreInteraction.HasMasterPassword();
Debug.Log($"has master password {result}");
}
public void GetUserInfo()
{
var userInfo = ParticleAuthCoreInteraction.GetUserInfo();
Debug.Log($"get user info {userInfo}");
}
public void OpenWebWallet()
{
var jsonString = "";
ParticleAuthCoreInteraction.OpenWebWallet(jsonString);
}
public async void OpenAccountAndSecurity()
{
try
{
var nativeResultData =
await ParticleAuthCore.Instance.OpenAccountAndSecurity();
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public void EvmGetAddress()
{
var address = ParticleAuthCoreInteraction.EvmGetAddress();
Debug.Log($"evm address: {address}");
}
public async void EvmPersonalSign()
{
try
{
var message = "Hello world";
var nativeResultData =
await ParticleAuthCore.Instance.EvmPersonalSign(message);
// var nativeResultData =
// await ParticleAuthCore.Instance.EvmPersonalSignUnique(message);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public async void EvmSignTypedData()
{
try
{
var txtAsset = Resources.Load<TextAsset>("TypedDataV4");
string typedData = txtAsset.text;
var chainId = ParticleNetwork.GetChainInfo().Id;
JObject json = JObject.Parse(typedData);
json["domain"]["chainId"] = chainId;
string newTypedData = json.ToString();
var nativeResultData =
await ParticleAuthCore.Instance.EvmSignTypedData(newTypedData);
// var nativeResultData =
// await ParticleAuthCore.Instance.EvmSignTypedDataUnique(newTypedData);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public async void EvmSendTransaction()
{
try
{
var address = ParticleAuthCoreInteraction.EvmGetAddress();
var transaction = await TransactionHelper.GetEVMTransacion(address);
var nativeResultData =
await ParticleAuthCore.Instance.EvmSendTransaction(transaction);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public void SolanaGetAddress()
{
var address = ParticleAuthCoreInteraction.SolanaGetAddress();
Debug.LogError($"solana address: {address}");
}
public async void SolanaSignMessage()
{
try
{
var message = "Hello Particle!";
var nativeResultData =
await ParticleAuthCore.Instance.SolanaSignMessage(message);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public async void SolanaSignTransaction()
{
try
{
var address = ParticleAuthCoreInteraction.SolanaGetAddress();
var transaction = await TransactionHelper.GetSolanaTransacion(address);
var nativeResultData =
await ParticleAuthCore.Instance.SolanaSignTransaction(transaction);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public async void SolanaSignAllTransactions()
{
try
{
var address = ParticleAuthCoreInteraction.SolanaGetAddress();
var transaction1 = await TransactionHelper.GetSolanaTransacion(address);
var transaction2 = await TransactionHelper.GetSolanaTransacion(address);
var nativeResultData =
await ParticleAuthCore.Instance.SolanaSignAllTransactions(new[] { transaction1, transaction2 });
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}
public async void SolanaSignAndSendTransaction()
{
try
{
var address = ParticleAuthCoreInteraction.SolanaGetAddress();
var transaction = await TransactionHelper.GetSolanaTransacion(address);
var nativeResultData =
await ParticleAuthCore.Instance.SolanaSignAndSendTransaction(transaction);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
}