Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,60 +1,15 @@
import CopyableNoFollow from '@site/src/components/CopyableNoFollow'
Use the Nethereum account created from the user's private key to get the EVM address:

In this reference, we're using the `Nethereum` library to demonstrate how to make blockchain calls
using it with Web3Auth.
```cs
using System;

# Package installation instructions
public string getAccount()
{
if (account == null)
{
throw new InvalidOperationException("Sign in before requesting an account.");
}

See the [official repository](https://github.com/Nethereum/Nethereum.Unity)

Install via **Package Manager** using OpenUpm:

- open Edit/Project Settings/Package Manager

- add a new **Scoped Registry** (or edit the existing OpenUPM entry)
- Name package.openupm.com

- URL <CopyableNoFollow url="https://package.openupm.com" plain />

- `Scope(s)` com.nethereum.unity

- click Save or Apply

- Open **Window/Package Manager**

- click **+**

- select Add package by name... or Add package from git URL...

- paste **com.nethereum.unity** into name

- paste **4.19.2** into version (or your preferred one)

- click **Add**

# Installing package for old version

- Download the latest `net461dllsAOT.zip` package from Nethereum's
[latest release](https://github.com/Nethereum/Nethereum/releases)

- Extract and the rename the folder to `NethereumLib` for easy identification.

- Move the folder to the `Assets/Plugins` folder of your Unity project.

- You might have to delete a few files from the `NethereumLib` fold er, if you're getting any errors
while building the project. For our implementation, we deleted the following files:
`Newtonsoft.Json.dll`, all the files starting with `System.*`, `UnityEngine.dll`,
`Nethereum.Web3Lite.dll`, `Nethereum.HdWallet.dll`, `NBitcoin.dll`, `Nethereum.RPC.Reactive.dll`
and `Common.Logging.Core.dll`.

:::info

We have followed [this guide](https://docs.nethereum.com/) to set up
the `Nethereum` package in our app. You can check their sample applications as well for a decent
reference.

You can also check the
[Web3Auth Unity Sample Apps](https://github.com/Web3Auth/web3auth-unity-examples), where we
have added the required packages.

:::
return account.Address;
}
```
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
```cs
using Nethereum.Web3;
using Nethereum.Util;
using Nethereum.Signer;
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.ABI.Encoders;
using Nethereum.Hex.HexTypes;
using Nethereum.Web3.Accounts;
using Nethereum.Web3.Accounts.Managed;

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

const string rpcURL = "" // EVM chain RPC URL
private const string rpcUrl = "<YOUR_RPC_URL>";

void Start()
{

web3Auth = GetComponent<Web3Auth>();

// Add Web3Auth Unity SDK Initialisation Code here

web3Auth.onLogin += onLogin;
web3Auth.onLogout += onLogout;
web3 = new Web3(rpcURL);
web3Auth = GetComponent<Web3Auth>();
// Add the Embedded Wallet SDK initialization code here.
web3Auth.onLogin += onLogin;
}

private void onLogin(Web3AuthResponse response)
{
privateKey = response.privKey;
var newAccount = new Account(privateKey);
account = newAccount;
privateKey = response.privateKey;
account = new Account(privateKey);
web3 = new Web3(account, rpcUrl);
}
// ...
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ the `Nethereum` package in our app. You can check their sample applications as w
reference.

You can also check the
[Web3Auth Unity Sample Apps](https://github.com/Web3Auth/web3auth-unity-examples), where we
have added the required packages.
[Unity SDK sample](https://github.com/Web3Auth/web3auth-unity-sdk/tree/master/Assets/Plugins/Web3AuthSDK/Samples).

:::
4 changes: 0 additions & 4 deletions embedded-wallets/connect-blockchain/evm/ethereum/unity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ While using the Embedded Wallets Unity SDK, you get the private key within the u

<InstallationSnippet />

## Chain details for Ethereum

<ChainDetailsEthereum />

## Initialize

<InitialisationSnippet />
Expand Down
4 changes: 0 additions & 4 deletions embedded-wallets/connect-blockchain/evm/monad/unity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ While using the Embedded Wallets Unity SDK, you get the private key within the u

<InstallationSnippet />

## Chain details for Monad

<ChainDetailsMonad />

## Initialize

<InitialisationSnippet />
Expand Down
41 changes: 27 additions & 14 deletions embedded-wallets/connect-blockchain/solana/unity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,38 @@ Alternatively, you can use other Solana Unity SDKs or create custom C# bindings

## Initialize

First, initialize the Web3Auth Unity SDK and retrieve the Ed25519 private key after successful authentication:
Initialize the Embedded Wallet SDK and retrieve the Ed25519 private key from the sign-in callback:

```csharp
using Web3Auth;

public class SolanaIntegration : MonoBehaviour
{
private Web3Auth web3Auth;
private string ed25519PrivateKey;

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

// After successful login
await web3Auth.login();

// Get Ed25519 private key for Solana
ed25519PrivateKey = await web3Auth.GetEd25519PrivKey();
public void login()
{
web3Auth.login(new LoginParams
{
authConnection = AuthConnection.GOOGLE,
curve = Curve.ED25519
});
}

Debug.Log("Ed25519 Private Key retrieved for Solana");
private void onLogin(Web3AuthResponse response)
{
ed25519PrivateKey = response.ed25519PrivateKey;
}
}
```
Expand All @@ -104,10 +114,13 @@ public class SolanaIntegration : MonoBehaviour

```csharp
// After successful Web3Auth login
string ed25519PrivateKey = await web3auth.GetEd25519PrivKey();
string ed25519PrivateKey = web3Auth.getEd25519PrivateKey();

// Convert to byte array if needed for Solana SDK
byte[] privateKeyBytes = Convert.FromHexString(ed25519PrivateKey);
byte[] privateKeyBytes = new byte[ed25519PrivateKey.Length / 2];
for (int index = 0; index < privateKeyBytes.Length; index++)
{
privateKeyBytes[index] = Convert.ToByte(ed25519PrivateKey.Substring(index * 2, 2), 16);
}
```

## Create a Solana keypair
Expand Down
143 changes: 143 additions & 0 deletions embedded-wallets/migration-guides/unity.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
title: Unity SDK v8 migration guide
sidebar_label: Unity SDK v8
description: Upgrade the MetaMask Embedded Wallet SDK for Unity from v7 to v8.
keywords: [migration, v8, v7, unity, web3auth, embedded wallets, csharp]
---

Unity SDK v8 updates authentication and Wallet Services to the latest service APIs.
It also renames several public types and properties.

:::caution Preserve wallet addresses

Don't change your client ID, Sapphire network, or authentication connection configuration during
the migration.
Changing these values can change your users' wallet addresses.

:::

## Install v8

Download the
[latest v8 `.unitypackage`](https://github.com/Web3Auth/web3auth-unity-sdk/releases/latest), remove
the previous SDK files from your project, and import the new package.

Ensure `Packages/manifest.json` includes Newtonsoft.Json:

```json
{
"dependencies": {
"com.unity.nuget.newtonsoft-json": "3.2.1"
}
}
```

## Update initialization

Rename `network` to `web3AuthNetwork`.
Replace `loginConfig` and `LoginConfigItem` with `authConnectionConfig` and
`AuthConnectionConfig`.

```cs
var connection = new AuthConnectionConfig
{
authConnectionId = "<YOUR_AUTH_CONNECTION_ID>",
authConnection = AuthConnection.GOOGLE,
clientId = "<YOUR_GOOGLE_CLIENT_ID>"
};

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

## Update sign-in parameters

Replace `Provider` with `AuthConnection`.
In `LoginParams`, rename `loginProvider` to `authConnection`.
Replace `Provider.JWT` with `AuthConnection.CUSTOM`.
For custom authentication, pass the dashboard connection ID as `authConnectionId`.

```cs
web3Auth.login(new LoginParams
{
authConnection = AuthConnection.CUSTOM,
authConnectionId = "<YOUR_AUTH_CONNECTION_ID>",
extraLoginOptions = new ExtraLoginOptions
{
id_token = "<YOUR_ID_TOKEN>",
userIdField = "sub"
}
});
```

Also rename these `ExtraLoginOptions` properties:

- `verifierIdField` to `userIdField`
- `isVerifierIdCaseSensitive` to `isUserIdCaseSensitive`

## Update response and key properties

Rename the response properties:

- `privKey` to `privateKey`
- `ed25519PrivKey` to `ed25519PrivateKey`

Rename the session key methods:

- `getPrivKey()` to `getPrivateKey()`
- `getEd25519PrivKey()` to `getEd25519PrivateKey()`

Update `UserInfo` property names:

- `aggregateVerifier` to `groupedAuthConnectionId`
- `verifier` to `authConnectionId`
- `verifierId` to `userId`
- `typeOfLogin` to `authConnection`

```cs
private void onLogin(Web3AuthResponse response)
{
var privateKey = response.privateKey;
var ed25519PrivateKey = response.ed25519PrivateKey;
}
```

## Update Wallet Services

Configure chains in the Embedded Wallets dashboard.
Replace `launchWalletServices(ChainConfig)` with `showWalletUI()`:

```cs
web3Auth.showWalletUI();
```

Remove `ChainConfig` from `request`.
Pass only the method and its parameters:

```cs
var requestParams = new JArray
{
"Hello World",
account.Address
};

web3Auth.request("personal_sign", requestParams);
```

Subscribe to `onSignResponse` to receive the request result.

## Verify the migration

1. Confirm the redirect URL matches the dashboard allowlist and the Unity deep-link configuration.
2. Test sign-in and sign-out on every target platform.
3. Confirm an existing user receives the same wallet address as before the migration.
4. Test custom and grouped authentication connections, if configured.
5. Test Wallet Services and signing requests on every configured chain.
Loading
Loading