# Integrate Embedded Wallets with the Monad Blockchain in Unity

> Integrate Embedded Wallets with the Monad Blockchain in Unity | Embedded Wallets

While using the Web3Auth Unity SDK, you get the private key within the user scope. This private key can interact with the [Nethereum Library](https://nethereum.com/) to make EVM based blockchain calls, like getting user's `account`, fetch `balance`, `sign transaction`, `send transaction`, `read` from and `write` to the smart contract, etc. We have highlighted a few here for getting you started quickly on that.

## Chain details for Monad

<Tabs
 defaultValue="mainnet"
  values={[
    { label: "Mainnet", value: "mainnet" },
    { label: "Testnet", value: "testnet" },
  ]}
>
<TabItem value="mainnet">

- **Chain ID:** 0x8f (143)
- **Public RPC URL:** `https://rpc.monad.xyz`
- **Public RPC URL 2:** `https://rpc1.monad.xyz`
- **Block Explorer Link:** `https://monadvision.com`
- **Ticker:** MON
- **Ticker Name:** Monad

</TabItem>

<TabItem value="testnet">

- **Chain ID:** 0x279f (10143)
- **Public RPC URL:** `https://testnet-rpc.monad.xyz`
- **Block Explorer Link:** `https://testnet.monadvision.com`
- **Ticker:** MON
- **Ticker Name:** Monad

</TabItem>
</Tabs>

## Installation

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

### Package installation instructions

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" />

  - `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` folder, 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.

:::

## Chain details for Monad

<Tabs
 defaultValue="mainnet"
  values={[
    { label: "Mainnet", value: "mainnet" },
    { label: "Testnet", value: "testnet" },
  ]}
>
<TabItem value="mainnet">

- **Chain ID:** 0x8f (143)
- **Public RPC URL:** `https://rpc.monad.xyz`
- **Public RPC URL 2:** `https://rpc1.monad.xyz`
- **Block Explorer Link:** `https://monadvision.com`
- **Ticker:** MON
- **Ticker Name:** Monad

</TabItem>

<TabItem value="testnet">

- **Chain ID:** 0x279f (10143)
- **Public RPC URL:** `https://testnet-rpc.monad.xyz`
- **Block Explorer Link:** `https://testnet.monadvision.com`
- **Ticker:** MON
- **Ticker Name:** Monad

</TabItem>
</Tabs>

## Initialize

```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 string privateKey;
    private Account account;

    const string rpcURL = "" // EVM chain RPC URL

    void Start()
    {

      web3Auth = GetComponent<Web3Auth>();

      // Add Web3Auth Unity SDK Initialisation Code here

      web3Auth.onLogin += onLogin;
      web3Auth.onLogout += onLogout;
      web3 = new Web3(rpcURL);
    }

    private void onLogin(Web3AuthResponse response)
    {
        privateKey = response.privKey;
        var newAccount = new Account(privateKey);
        account = newAccount;
    }
// ...
}
```

## Get account

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

# Package installation instructions

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" />

  - `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.

:::

## Get balance

```cs
public void getBalance() {
  if (account == null) {
    Debug.Log("Please Login First");
    return;
  }
  // focus-next-line
  var balance = web3.Eth.GetBalance.SendRequestAsync(account.Address).Result.Value;

  Debug.Log(balance);
}
```

## Sign a message

```cs
public void signMessage() {
  if (account == null) {
    Debug.Log("Please Login First");
    return;
  }
  // focus-start
  var msg = "test message 19/01/2023 02:55PM";
  var signer = new EthereumMessageSigner();
  var signature = signer.EncodeUTF8AndSign(msg, new EthECKey(privateKey));
  // focus-end

  Debug.Log(signature);
}
```

## Send transaction

```cs
public async void sendTransaction() {
  if (account == null) {
    Debug.Log("Please Login First");
    return;
  }
  // focus-start
  var toAddress = "0x2E464..82D5057fB507Cc21";
  var transaction = await web3.TransactionManager.SendTransactionAsync(account.Address, toAddress, new Nethereum.Hex.HexTypes.HexBigInteger(1));
  // focus-end

  Debug.Log(transaction);
}
```
