> ## Documentation Index
> Fetch the complete documentation index at: https://developers.particle.network/llms.txt
> Use this file to discover all available pages before exploring further.

# Unity (C#) Desktop - Auth

> Interacting with Particle Auth within games built on Unity using C#.

## Particle Auth for Unity on Windows/macOS

The **Particle Auth** [Unity SDK](https://github.com/Particle-Network/particle-unity) is the key tool for integrating Particle's **Wallet-as-a-Service** into Unity-based games.

This SDK streamlines **configuration**, **integration**, and **interaction**, making it the only library needed for most applications.

It supports end-to-end usage of Particle Network with **email**, **phone**, or **custom JWT authentication**.

While its structure is similar to the [Web (JavaScript/TypeScript)](/social-logins/auth/desktop-sdks/web) SDK, there are several key differences, **detailed below**.

<Warning>
  <p>Due to limitations with Webview, Particle Auth for Unity on Windows & macOS does not include most built-in social logins</p>
  <p>Options include email, phone, and custom JWT authentication (indicated by 'email', 'phone', or 'jwt').</p>
</Warning>

***

## Getting Started

To start with the **Particle Auth** **Unity** SDK on **Windows** and **macOS**, ensure you meet the prerequisites: a minimum **Unity** version and a **Unity** package for handling authentication popups.

## Prerequisites

* Unity **2021.3.35f1** or later.

* Requires one of the following packages:

  * ​**Recommended**: 3D WebView for Windows and macOS (Web Browser) from Vuplex, version **4.3.3** or higher.

  * Other web browser packages will also work here if necessary.

## Quickstart

Before diving into the specifics of SDK initialization and use, the best way to get started and explore a live implementation of the Unity SDK is through the **Windows/macOS** demo included within the [GitHub repository](https://github.com/Particle-Network/particle-unity).

This demo will consist of initializing the SDK and, as previously detailed, a Webview-based authentication menu for [MPC-TSS](/social-logins/mpc-tss) login, enabling interaction with the resulting wallet.

#### Quickstart demo installation

To start testing the included demo, download the **Windows/macOS** demo from [GitHub](https://github.com/Particle-Network/particle-unity/tree/2e08f144327a25a1f28098defa182155d120f177/Assets/ParticleNetwork/Windows).

If you've already imported the **SDK** from the [linked repository](https://github.com/Particle-Network/particle-unity), follow these steps to initialize the demo:

1. Open the Windows/macOS **Auth** demo scene in the Unity editor.

2. Click the **Particle Init** button to initialize the SDK.

3. Click **Login** to create an account instance and enable the sample functions.

## Initialization

After exploring the SDK's implementation through the **demo**, let's understand and dive into the **configuration**, which includes some structural deviations from the Web SDK.

***

### Initializing the Particle Auth SDK

1. **Create a GameObject:**
   * Add a new `GameObject` to your scene.
   * Attach the `ParticleSystem` script to this GameObject.

2. **Attach Canvas WebView:**
   * Attach the `CanvasWebViewPrefab` to the `ParticleSystem` script.

3. **Add Particle Unity RPC:**
   * Put a `ParticleUnityRpc` prefab into your scene.
   * Update the prefab with your `project id`, `app id`, and `client key`.

4. **Configure the ParticleSystem:**
   * Before using the SDK, you must configure the `ParticleSystem` (similar to the `ParticleNetwork` in the Web SDK).

   * Execute this configuration by calling the `Init` method on `ParticleSystem.Instance` with the following parameters:

   * **`config`**: Includes `ParticleConfigSecurityAccount` and `ParticleConfigWallet`.

   * **`theme`**: Controls the theme settings such as dark or light mode, whether to display the wallet or show the close button.

   * **`language`**: A string indicating the UI language, options include 'en-US', 'zh-CN', 'zh-TW', 'ja-JP', or 'ko-KR'.

   * **`chainInfo`**: An object that specifies the primary blockchain to be used.

```csharp C# theme={null}
var supportChains = new List<SupportChain>
                { new SupportChain(ChainInfo.EthereumSepolia.Name, ChainInfo.EthereumSepolia.Id) };
var config = new ParticleConfig(new ParticleConfigSecurityAccount(1, 1),
                                new ParticleConfigWallet(true, supportChains, null));

var theme = new ParticleTheme
  {
  UiMode = "dark",
  DisplayWallet = true,
  DisplayCloseButton = true
  };

var language = "en-US";

var chainInfo = ChainInfo.EthereumSepolia;

ParticleSystem.Instance.Init(config.ToString(), theme.ToString(), language, chainInfo);
```

Among these parameters, the `ParticleUnityRpc` prefab containing `project id`, `app id` and `client key` are the most important. It directly connects your instance of Particle's Wallet-as-a-Service with your configurations in the [Particle dashboard](https://dashboard.particle.network/).

<Note>Find a full rundown on how to set up a project and find the required keys in the [Dashboard Guide ](/social-logins/dashboard).</Note>

### Examples of utilization

#### Login

`ParticleSystem.Instance.Login` displays the login popup, set to 'email', 'phone', or custom JWT authentication with 'jwt'.

This popup acts as the **primary mechanism** for facilitating account creation.

```csharp C# theme={null}
// PreferredAuthType: email, phone, or jwt
// Account: Required when using jwt 
var loginResult = await ParticleSystem.Instance.Login(PreferredAuthType.email, "");
Debug.Log($"Login result {loginResult}"); // Contains user information
```

#### SignMessage

`ParticleSystem.Instance.SignMessage` enables the signing of a basic string.

This can be passed directly within `SignMessage` for **EVM** chains, as shown below.

For **Solana**, you'll need to convert this string to base58 before `SignMessage` will function properly. The confirmation popup will display this string, base58 or otherwise, in UTF-8.

```csharp C# theme={null}
var signature = await ParticleSystem.Instance.SignMessage("GM, Particle!");
Debug.Log($"SignMessage signature: {signature}");
```

#### SignAndSendTransaction

The `ParticleSystem.Instance.SignAndSendTransaction` method takes a transaction object constructed by `ParticleSystem.Instance.MakeEvmTransaction` (for EVM chains). It then prompts the user for confirmation (signature).

Once the user confirms, the transaction will be sent.

```csharp C# theme={null}
var transaction = ParticleSystem.Instance.MakeEvmTransaction("0x16380a03f21e5a5e339c15ba8ebe581d194e0db3", "0xA719d8C4C94C1a877289083150f8AB96AD0C6aa1", "0x", "0x123123");
var signMessageResult = await ParticleSystem.Instance.SignAndSendTransaction(transaction);
Debug.Log($"SignAndSendTransaction signature: {signature}");
```

#### SignTypedData

`ParticleSystem.Instance.SignTypedData` facilitates the signature of structured data; by default, this uses `eth_signTypedData_v4`.

For more information on `signTypedData`, see the [Web (JavaScript/TypeScript)](/social-logins/auth/desktop-sdks/web) page.

```csharp C# theme={null}
string typedDataV4 = "";
var signMessageResult = await ParticleSystem.Instance.SignTypedData(typedDataV4, SignTypedDataVersion.Default);
Debug.Log($"SignTypedData signature: {signature}");
```

#### SignTransaction

`ParticleSystem.Instance.SignTransaction` is a **Solana-specific** method for requesting a signature for a given transaction.

This will sign (but not send) a transaction.

```csharp C# theme={null}
 string transaction = "";
var signMessageResult = await ParticleSystem.Instance.SignTransaction(transaction);
Debug.Log($"SignTransaction signature: {signature}");
```

#### SignAllTransactions

`ParticleSystem.Instance.SignAllTransactions` is the plural of those mentioned above; this is also \**Solana-specific*

```csharp C# theme={null}
List<string> transactions = new List<string> { "" }; // base58 strings
var signMessageResult = await ParticleSystem.Instance.SignAllTransactions(transactions);
Debug.Log($"SignAllTransactions signature: {string.Join(", ", signatureList)}");
```

#### OpenWebWallet

`ParticleSystem.Instance.OpenWebWallet` can open the web wallet.

```csharp C# theme={null}
ParticleSystem.Instance.OpenWebWallet();
// If you prefer to open wallet with a smart account selected, you can pass the account name, such as
ParticleSystem.Instance.OpenWebWallet(AAAccountName.BICONOMY_V2());
```

## Master reference

Below is a table containing every relevant method provided through `ParticleSystem` alongside specific parameters and a short description for a direct, raw view.

For methods listed that needed to be covered in the above examples, live implementation often mimics the standard structure covered throughout this document.

| Class          | Methods                | Parameters                                  |
| -------------- | ---------------------- | ------------------------------------------- |
| ParticleSystem | Init                   | config, theme, language, chainName, chainId |
| ParticleSystem | Login                  | preferredAuthType, account                  |
| ParticleSystem | SignMessage            | message                                     |
| ParticleSystem | SignAndSendTransaction | transaction                                 |
| ParticleSystem | SignTypedData          | message, version                            |
| ParticleSystem | SignTransaction        | transaction                                 |
| ParticleSystem | SignAllTransactions    | transactions                                |
| ParticleSystem | MakeEvmTransaction     | from, to, data, value                       |
| ParticleSystem | UpdateChainId          | chainId                                     |
| ParticleSystem | UpdateChainName        | chainName                                   |
