# Metamask Wallet

LYNC Metamask Wallet SDK is a one-stop solution for game developers to easily integrate Metamask into their game engine and deploy their game on multiple networks with just a few clicks. This SDK allows game developers to monitor gamers’ data via LYNC analytics system and update the SDK without leaving the game engine.

<figure><img src="/files/jDlzslJ7Aqd3paGIkJf0" alt=""><figcaption><p>Integrate Metamask wallet inside any game using LYNC SDK</p></figcaption></figure>

## Get Your API Key&#x20;

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

## Installation

Download the LYNC - Metamask Wallet SDK from [**here**](https://github.com/LYNC-WORLD/Metamask-Unity-Wallet-SDK/releases)

Example Project- <https://github.com/LYNC-WORLD/Metamask-Unity-WebGL-SDK>

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

<figure><img src="/files/WKpr8TZQ2Hc38raIfTxY" alt="" width="561"><figcaption><p>Assets -> Import Package -> Custom Package</p></figcaption></figure>

Once the Metamask Wallet SDK package has finished importing into your Unity project, you can begin integrating it into your game. To do this, open the **ConnectWallet** scene provided by the LYNC - Metamask SDK.\
\
&#x20;                                            **Path : Assets ->LYNC-Metamask-SDK -> Scenes**

<figure><img src="/files/Q8qZE2h5ZYYVJEQvBCyr" alt="" width="563"><figcaption><p><strong>Assets ->LYNC-Metamask-SDK -> Scenes</strong></p></figcaption></figure>

## Choose blockchain network&#x20;

{% hint style="info" %}
If you haven't generated an API Key, please check [#get-your-api-key](#get-your-api-key "mention")
{% endhint %}

the After opening **ConnectWallet** scene, Go to **Interface.** In the "Inspector" window, go to the API key & Enter the **API key**.&#x20;

<figure><img src="/files/h5zomTaBJeDfVnDeF73S" alt="" width="563"><figcaption><p>Enter the API key</p></figcaption></figure>

To choose the blockchain network, simply go to the **CurrentChain** drop-down menu and pick the network of your preference to deploy your game on.

<figure><img src="/files/9VKBJI1pAJD7gJvz5CMc" alt="" width="375"><figcaption><p>Interface -> CurrentChain -> Choose Your Chain</p></figcaption></figure>

## Integrating the Transaction Layer

The Transactions are divided into 2 parts:

1. No Code Transactions
2. Modular Transactions

<mark style="color:yellow;">**Note: Make sure to have "TransactionManager.cs" in your scene.**</mark>

#### No-code Transaction

&#x20;Check the No-Code-Transaction Scene in the Scenes folder.

<figure><img src="/files/l78LK9kVqEZQGgVWAVz1" alt="" width="563"><figcaption><p>No Code Transaction Scene</p></figcaption></figure>

Check the No-Code TransactionExample GameObject, you can just pass in a few parameters to write on any custom contract inside the game.

Just pass the following parameters:

1. Contract Address - Type any contract address on the chain you selected in the LYNCInterface GameObject.
2. ABI - You can get the contract ABI of a verified contract on the explorer.<br>

   <figure><img src="/files/5T4buGzSfStpIYMHF0MP" alt="" width="563"><figcaption><p>Copy ABI from explorer</p></figcaption></figure>
3. Function Name - Write the exact function name from the contract
4. Cost - The cost required to do the transaction, if it's free you can pass 0 else pass the value in wei.
5. Arguments - The arguments required by the transaction, are left blank if none.

#### Modular Transactions

Check the No-Code-Transaction Scene in the Scenes folder.

<figure><img src="/files/67BDizJBnDEF0kpntoPc" alt="" width="563"><figcaption><p>Transaction Scene</p></figcaption></figure>

Check the TransactionExample GameObject, it has a TransactionExample.cs file attached. \
This example contains 3 types of transaction transactions, ERC-721, ERC-1155 and ERC-20.

<figure><img src="/files/86RkeIIOLZ0xzQK6Zwub" alt="" width="563"><figcaption><p>Assets/LYNC-Metamask-SDK/Scripts/TransactionExample.cs</p></figcaption></figure>

In this example:

1. send20Trx is a button to disable the button click once the transaction is initiated.
2. contractAddress - is the contract address for a custom transaction. [(In this case, it's an ERC-20 contract address on Mumbai Testnet)](https://mumbai.polygonscan.com/address/0xab2C8D39B611Eee2c0ABc9C12Af0221c1e861879#code)
3. ABI - [You can get the contract ABI of a verified contract on the explorer.](https://mumbai.polygonscan.com/address/0xab2C8D39B611Eee2c0ABc9C12Af0221c1e861879#code)
4. functionName - Write the exact function name from the contract [(In this case, sendToken)](https://mumbai.polygonscan.com/address/0xab2C8D39B611Eee2c0ABc9C12Af0221c1e861879#writeContract#F5)
5. cost - The cost required to do the transaction, if it's free you can pass 0 else pass the value in wei. (In this case, as the function is not payable the value is 0).
6. ParametersOfFunctions - You can pass in the arguments required for the transaction. (In this example, the argument is how much amount you want to send, [10000000000000000 is the value in wei, i.e 0.01 eth.](https://eth-converter.com/) You can pass n number of arguments separated with a comma( , ) ).
7. args - Converts compatible to be a JSON
8. Sending transaction -&#x20;

   ```csharp

   TransactionManager.Instance.SendTransaction(LoadingScreen, contractAddress, ABI, functionName, args, cost, On20TrxCompleted, On20TrxFailed);

   The above example explains a requirement for doing transactions.

   You can use the "TransactionManager.Instance.SendTransaction()" to send transactions from anywhere in the project, make sure to add the TransactionManager.cs file in the scene.
   ```

It takes a LoadingScreen GameObject, contractAddress, ABI, functionName, args, and cost, as explained above and 2 more functions of type "System.Action\<string>".

These are not compulsory functions but they handle the Transaction Success or Failure.

**On20TrxCompleted** - Handles once the transaction is completed. (It returns a transaction hash).

**On20TrxFailed** - Handles if the transaction failed. (It returns a reason for transaction failure).

## Integrating Connet Wallet scene into the build&#x20;

To deploy your Unity project, it's necessary to set up the Player Settings in Unity. Follow these steps to select the LYNC WebGL template.

<figure><img src="/files/WBhVY5MLBSvVvWLzOpx1" alt="" width="563"><figcaption><p>File -> Build Settings</p></figcaption></figure>

In the "**Build Settings**" window, place **ConnectWallet** and **FetchWallet** at the top of this section.&#x20;

<figure><img src="/files/3n949JigLTLSBJgJ67qn" alt=""><figcaption><p>Add ConnectWallet &#x26; FetchWallet Scene to the top of Scenes in Build</p></figcaption></figure>

Go to "**Player Settings**" and navigate to "**Resolution and Presentation**". **Select LYNC - Template** in WebGL Template

<figure><img src="/files/D50brCPnJKV2x3SG51Dv" alt="" width="563"><figcaption><p>Player Settings -> Resolution and Presentation -> Select LYNC - Template</p></figcaption></figure>

After completing all the necessary steps and configuring the Player Settings with the LYNC WebGL template, you can now build and run your game.

* To do this, go to "**File**" on the top menu bar in the Unity editor and select "**Build and Run**."&#x20;

<figure><img src="/files/uQWNejbYbagYbYLNg5FG" alt=""><figcaption><p>Build and Run </p></figcaption></figure>

Congratulation, you have successfully integrated the Metamask wallet with your favourite blockchain network using LYNC SDK. \
\
NOTE: If you wish to use wallet address inside game after user's wallet is connected, use:

```
PlayerPrefs.GetString("WalletAddress");
```

If you face any error, while Build and Run.\
\
PLEASE ADD, Unity package install by git link

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

<figure><img src="/files/HEmQWGKhNgzaJI3Hfb8X" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lync-1.gitbook.io/lync/products/metamask-wallet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
