# LYNC Account Abstraction SDK

LYNC Unity Account Abstraction SDK, your solution to seamless gamer onboarding in Web3 Games! Enable effortless logins via socials, wallets, email, and more. Integrate swiftly into any game on Mac, Windows, Android, iOS, or browser. Simplify the gaming experience with LYNC AA SDK, connecting gamers effortlessly.

## Get your API Key

Please get your API key before downloading the SDK from [**here**](https://www.lync.world/form.html)

## Installation

Download the LYNC Account Abstraction SDK from [Here](https://github.com/LYNC-WORLD/LYNC-Unity-AA)

Import the SDK .unitypackage file to your project. or simply drag and drop .unitypackage file to your project.

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FdDzWzt5kkCqpWZTINSsu%2FLYNC%20wallet%20sdk.png?alt=media&#x26;token=65ae978c-fa8b-4eb5-a2ba-548146b3bb14" alt=""><figcaption><p>Assets -> Import Package -> Custom Package</p></figcaption></figure>

\
Once the Account Abstraction SDK package has finished importing into your Unity project, you can begin integrating it into your game.

The Folder structure looks like this

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FrdCExDV2GFsa0feO0aIz%2FScreenshot%202023-10-30%20at%201.02.07%E2%80%AFPM.png?alt=media&#x26;token=1d441316-c909-4d5d-8306-bc9053000384" alt="" width="279"><figcaption><p>SDK Folder Structure</p></figcaption></figure>

### Integrating AA SDK in Unity

There are 2 Example Projects present in the SDK:\
Assets -> LYNC-AA-SDK -> Example / Example-2

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FDxY6OEVTVzwMMSCRcile%2FScreenshot%202023-10-30%20at%201.20.22%E2%80%AFPM.png?alt=media&#x26;token=0df1470b-5598-4f2d-915c-1f25fcf0cd2a" alt=""><figcaption><p>Example Projects</p></figcaption></figure>

You can find the example scene in the folders. Simply pass the API key in lyncManager GameObject.

To test, Build and Run after adding this scene in (Scene in Build).\ <br>

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FJoAjijoyTGcJ7ZN7b7Jt%2FScreenshot%202023-10-30%20at%201.22.52%E2%80%AFPM.png?alt=media&#x26;token=84ced955-43e5-40de-b0bf-b535797193fd" alt="" width="375"><figcaption><p>Pass LYNC API Key</p></figcaption></figure>

### **Setup the Project**

To use LYNC Manager Prefab, it needs to be attached to the first scene. This will serve as the starting point for your project.

In LYNC Manager Prefab, be sure to provide the following details:

1. LYNC API Key ([The API Key can be generated from here](https://lync.world/form.html))
2. Choose chain
3. Pass in the Dapp API Key ([The API key can be generated from the Biconomy Dashboard](https://dashboard.biconomy.io/) )
4. Web3 Auth Client ID ([The API key can be generated from the Web3 Auth Dashboard](https://dashboard.web3auth.io/login))
5. Pass a deep link name (example: lync/gameName etc.)

### Integrating Login or Transaction Layer via Account Abstraction in Unity

Login and Transactions can be done once the action is triggered.

The Sample Code for Login can be found at LoginTransactionExample.cs and ExampleLogin.cs

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FchSK1xX1PX9xyxQ1uJsQ%2FScreenshot%202023-10-30%20at%201.43.10%E2%80%AFPM.png?alt=media&#x26;token=db56b9a8-c7b4-47e2-a945-71083200b560" alt=""><figcaption><p>Assets -> LYNC-AA-SDK -> Example -> Scripts -> ExampleLogin.cs</p></figcaption></figure>

**Note: Make sure to Import LYNC.**

```csharp
using LYNC;
using LYNC.Wallet;
```

**Example (Event Trigger):**

LYNC ready Should be a function which has an argument of type "LyncManager"

<pre class="language-csharp"><code class="lang-csharp"><strong>LyncManager.onLyncReady += LyncReady;
</strong><strong>
</strong>private void LyncReady(LyncManager Lync)
    {
        // Once LYNC is ready, you can do any steps like Login, Logout, Transactions etc.
    }
</code></pre>

**To Login:**

```csharp
Lync.WalletAuth.ConnectWallet((wallet) =>
{
    addressTxt.text = "Wallet Address: " + wallet.publicAddress;
    loginDateTxt.text = "Login Date: " + wallet.loginDate.ToString();
});
```

**To Logout:**

<pre class="language-csharp"><code class="lang-csharp"><strong>Lync.WalletAuth.Logout();
</strong></code></pre>

**To do transactions:**

To do transactions, TokenExample.cs and LoginTransactionExample.cs can be taken as a reference.

Pass in the Contract Address and Function Name Example: MintNFT(). MintNFT(unit256 id, unit256 amount)

Args are not compulsory parameters, but if the function accepts any argument, make sure to pass them.

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2F8ovVnpwBQAMrIvW2VTNt%2FScreenshot%202023-09-15%20at%2010.35.09%20AM.png?alt=media&#x26;token=6176397c-ed47-40e5-8c67-6634f807c709" alt=""><figcaption><p>Token Transactions</p></figcaption></figure>

To do it from the script:

```csharp
LyncManager.Instance.blockchainMiddleware.SendTransaction(contractAddress, functionName, args, onSuccess,onError);
```

onSuccess: Once the transactions are completed, this handles what to do.

onError: If the transactions failed, this handles what to do.

### Setup Gasless Transactions with Biconomy

To enable gasless transactions via biconomy, Register a new paymaster on the [Biconomy Dashboard](https://dashboard.biconomy.io).&#x20;

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FMzBE3oNHhzn83caWAnTe%2FScreenshot%202023-10-30%20at%203.51.21%E2%80%AFPM.png?alt=media&#x26;token=644f9fdf-3c70-498c-a47f-04e5df5dea9d" alt="" width="482"><figcaption></figcaption></figure>

Once done, Get the API Key and Pass it in to the [LYNC Manager](#setup-the-project).

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FPrmv3PLIXfSZkmYT8PHx%2FScreenshot%202023-10-30%20at%203.52.41%E2%80%AFPM.png?alt=media&#x26;token=d3407b05-fd02-47d6-9a3e-f46118269b56" alt=""><figcaption><p>Bicnomy API Key</p></figcaption></figure>

Setup the gas tank, in Policies create a new one and pass the contract address

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FNTjROLBhT9KjbBvMPIxS%2FScreenshot%202023-10-30%20at%203.58.25%E2%80%AFPM.png?alt=media&#x26;token=45f329ef-c7b9-4e00-a00a-c5a1aefbd200" alt="" width="124"><figcaption><p>Contract Address setup</p></figcaption></figure>

That's it, now you can do the gasless transaction on this contract address passing in the LYNC AA SDK.

#### Some common bugs and their resolutions

**Problem**: The type name 'HttpUtility' could not be found in the namespace 'System.Web'.

<pre class="language-csharp"><code class="lang-csharp"><strong>Assets\LYNC-AA-SDK\Auth\DeepLink\DeepLinkManager.cs(76,35):
</strong>error CS1069: The type name 'HttpUtility' could not be found in the namespace 'System.Web'.
This type has been forwarded to assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 
Consider adding a reference to that assembly.
</code></pre>

**Solution**:&#x20;

Change the API Compatibility Level\
To change the . NET profile, go to Edit > Project Settings > Player >Other settings.

Please change the .NET to 2.1 or 2

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FzSSIJvRWLmCs4kuTdqUL%2Fphoto_6197506361110149446_x.jpg?alt=media&#x26;token=3f7fd139-3537-4439-baad-9e469f7a7b45" alt=""><figcaption><p>Change the .NET Version</p></figcaption></figure>

**Problem:** Newtonsoft JSON is missing.

**Solution**: Please, Add this as a git URL in adding package

```csharp
com.unity.nuget.newtonsoft-json
```

<figure><img src="https://2257492769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3h3YUWYt8sR5rHLOIeFc%2Fuploads%2FGSxOxaOwNGPgGO0zfoXY%2FScreenshot%202023-10-31%20at%2011.42.26%E2%80%AFAM.png?alt=media&#x26;token=e1e281ac-ddb9-477f-926d-211cff424208" alt="" width="563"><figcaption><p>Add newtonsoft</p></figcaption></figure>
