> For the complete documentation index, see [llms.txt](/llms.txt).

# Embedded Wallets SDK for Unity

## Overview[​](#overview "Direct link to Overview")

The MetaMask Embedded Wallet SDK for Unity provides social and custom authentication for games and other Unity applications. The SDK supports Android, iOS, WebGL, macOS, and Windows.

## Requirements[​](#requirements "Direct link to Requirements")

- Unity Editor 2019.4.9f1 or greater
- .Net Framework 4.x
- Basic knowledge of C# and Unity development

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

- Set up your project on the [Embedded Wallets dashboard](https://developer.metamask.io/)

tip

See the [dashboard setup](/embedded-wallets/dashboard/) guide to learn more.

## Installation[​](#installation "Direct link to Installation")

Install the MetaMask Embedded Wallet SDK for Unity using the following method.

### Download Unity package[​](#download-unity-package "Direct link to Download Unity package")

Download the [latest .unitypackage](https://github.com/Web3Auth/web3auth-unity-sdk/releases/latest) and import it into your Unity project.

If you're upgrading from v7, follow the [Unity SDK v8 migration guide](/embedded-wallets/migration-guides/unity/).

warning

You may encounter errors when importing this package into your existing project.

`The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)`

To fix this problem you need to add the following line into the dependencies object which is inside the `Packages/manifest.json` file.

/Packages/manifest.json

```
"com.unity.nuget.newtonsoft-json": "3.2.1"

```

### Configure Web3Auth project[​](#configure-web3auth-project "Direct link to Configure Web3Auth project")

1. Create or select an Embedded Wallets project in the [MetaMask Developer dashboard](https://developer.metamask.io/).
2. Add `<YOUR_SCHEME>://<YOUR_APP_PACKAGE_NAME>/auth` to **Allowlist URLs**.
3. Copy your client ID.
4. In Unity, select **Window > Web3Auth > Generate Deep Link**, enter the same redirect URL, and select **Generate**.

## Initialize Web3Auth[​](#initialize-web3auth "Direct link to Initialize Web3Auth")

### 1. Add the Web3Auth component[​](#1-add-the-web3auth-component "Direct link to 1. Add the Web3Auth component")

Add the SDK's `Web3Auth` component to a game object. Create a separate script for your authentication logic and attach it to the same game object:

/Assets/AuthManager.cs

```
using System;
using System.Collections.Generic;
using UnityEngine;

public class AuthManager : MonoBehaviour
{
    private Web3Auth web3Auth;

    void Start() {}
    public void login() {}
    private void onLogin(Web3AuthResponse response) {}
    public void logout() {}
    private void onLogout() {}
}

```

Declare a field for the SDK component:

```
private Web3Auth web3Auth;

```

Get the component in `Start()`:

```
web3Auth = GetComponent<Web3Auth>();

```

### 2. Configure Web3Auth options[​](#2-configure-web3auth-options "Direct link to 2. Configure Web3Auth options")

After instantiation, within your `Start()` function, set up the Web3Auth Options:

```
web3Auth.setOptions(new Web3AuthOptions(){
    clientId = "<YOUR_CLIENT_ID>",
    web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET,
    redirectUrl = new Uri("<YOUR_SCHEME>://<YOUR_APP_PACKAGE_NAME>/auth"),
});

```

### 3. Set up event handlers[​](#3-set-up-event-handlers "Direct link to 3. Set up event handlers")

Set up event handlers for login and logout events:

```
void Start()
{
    web3Auth = GetComponent<Web3Auth>();
    web3Auth.setOptions(new Web3AuthOptions()
    {
        clientId = "<YOUR_CLIENT_ID>",
        web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET,
        redirectUrl = new Uri("<YOUR_SCHEME>://<YOUR_APP_PACKAGE_NAME>/auth"),
    });

    // Set up event handlers
    web3Auth.onLogin += onLogin;
    web3Auth.onLogout += onLogout;
}

private void onLogin(Web3AuthResponse response)
{
    Debug.Log("Login successful!");
    var privateKey = response.privateKey;
}

private void onLogout()
{
    Debug.Log("Logout successful!");
}

```

## Advanced configuration[​](#advanced-configuration "Direct link to Advanced configuration")

The Web3Auth Unity SDK offers a rich set of advanced configuration options:

- **[Custom authentication](/embedded-wallets/sdk/unity/advanced/custom-authentication/):** Define authentication methods.
- **[Whitelabeling and UI customization](/embedded-wallets/sdk/unity/advanced/whitelabel/):** Personalize the modal's appearance.
- **[Multi-Factor Authentication (MFA)](/embedded-wallets/sdk/unity/advanced/mfa/):** Set up and manage MFA.
- **[Dapp share](/embedded-wallets/sdk/unity/advanced/dapp-share/):** Share dapp sessions across devices.

tip

See the [advanced configuration sections](/embedded-wallets/sdk/unity/advanced/) to learn more about each configuration option.

- Basic Configuration
- Advanced Configuration

```
web3Auth = GetComponent<Web3Auth>();

web3Auth.setOptions(new Web3AuthOptions(){
    clientId = "<YOUR_CLIENT_ID>",
    web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET,
    redirectUrl = new Uri("<YOUR_SCHEME>://<YOUR_APP_PACKAGE_NAME>/auth"),
});

```

```
web3Auth = GetComponent<Web3Auth>();

var authConnection = new AuthConnectionConfig()
    {
        authConnectionId = "<YOUR_AUTH_CONNECTION_ID>",
        authConnection = AuthConnection.GOOGLE,
        clientId = "<YOUR_GOOGLE_CLIENT_ID>"
    };

web3Auth.setOptions(new Web3AuthOptions(){
    clientId = "<YOUR_CLIENT_ID>",
    web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET,
    redirectUrl = new Uri("<YOUR_SCHEME>://<YOUR_APP_PACKAGE_NAME>/auth"),
    authConnectionConfig = new List<AuthConnectionConfig>
    {
        authConnection
    },
    mfaSettings = new MfaSettings(
        new MfaSetting(true, 1, true),
        new MfaSetting(true, 2, true),
        new MfaSetting(true, 3, false),
        new MfaSetting(true, 4, false),
        null,
        null
    )
});

```

## Blockchain integration[​](#blockchain-integration "Direct link to Blockchain integration")

Web3Auth is blockchain agnostic, enabling integration with any blockchain network. We recommend using the **Nethereum Library** for Ethereum integration.

### Ethereum integration[​](#ethereum-integration "Direct link to Ethereum integration")

tip

We recommend you use the [Nethereum Library](https://docs.nethereum.com/) for making the blockchain calls. See [how to integrate Nethereum with Web3Auth](/embedded-wallets/connect-blockchain/evm/ethereum/unity/).

For Ethereum integration, you can get the private key and use it with Nethereum:

```
using Nethereum.Web3;
using Nethereum.Web3.Accounts;

public class Web3AuthScript : MonoBehaviour
{
    private Web3 web3;
    private Web3Auth web3Auth;
    private string privateKey;
    private Account account;

    private const string rpcUrl = "<YOUR_RPC_URL>";

    void Start()
    {
        web3Auth = GetComponent<Web3Auth>();
        // Add the Embedded Wallet SDK initialization code here.
        web3Auth.onLogin += onLogin;
    }

    private async void onLogin(Web3AuthResponse response)
    {
        privateKey = response.privateKey;
        account = new Account(privateKey);
        web3 = new Web3(account, rpcUrl);
        var balance = await web3.Eth.GetBalance.SendRequestAsync(account.Address);
    }
}

```

### Solana integration[​](#solana-integration "Direct link to Solana integration")

For Solana integration, you can get the Ed25519 private key:

```
private void onLogin(Web3AuthResponse response)
{
    var ed25519PrivateKey = response.ed25519PrivateKey;
    // Use Ed25519 private key with Solana libraries
}

```
