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

# Integrate Embedded Wallets with the Cronos Blockchain in Unity

While using the Embedded Wallets 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.

## Chain details for Cronos[​](#chain-details-for-cronos "Direct link to Chain details for Cronos")

- Mainnet
- Testnet

- **Chain ID:** 0x19
- **Public RPC URL:** `https://evm.cronos.org`
- **Display Name:** Cronos Mainnet
- **Block Explorer Link:** `https://cronoscan.com`
- **Ticker:** CRO
- **Ticker Name:** Cronos

- **Chain ID:** 0x152
- **Public RPC URL:** `https://evm-t3.cronos.org`
- **Display Name:** Cronos Testnet
- **Block Explorer Link:** `https://testnet.cronoscan.com`
- **Ticker:** TCRO
- **Ticker Name:** Test Cronos

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

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

### Package installation instructions[​](#package-installation-instructions "Direct link to 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 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[​](#installing-package-for-old-version "Direct link to 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 [Unity SDK sample](https://github.com/Web3Auth/web3auth-unity-sdk/tree/master/Assets/Plugins/Web3AuthSDK/Samples).

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

```
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 void onLogin(Web3AuthResponse response)
    {
        privateKey = response.privateKey;
        account = new Account(privateKey);
        web3 = new Web3(account, rpcUrl);
    }
}

```

## Get account[​](#get-account "Direct link to Get account")

Use the Nethereum account created from the user's private key to get the EVM address:

```
using System;

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

    return account.Address;
}

```

## Get balance[​](#get-balance "Direct link to Get balance")

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

  Debug.Log(balance);
}

```

## Sign a message[​](#sign-a-message "Direct link to Sign a message")

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

  Debug.Log(signature);
}

```

## Send transaction[​](#send-transaction "Direct link to Send transaction")

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

  Debug.Log(transaction);
}

```
