Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to connect and sign in Unity #1023

Merged
merged 6 commits into from Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions wallet/how-to/sign-data/connect-and-sign.md
Expand Up @@ -8,8 +8,8 @@ tags:

# Connect and sign

You can connect to MetaMask and sign data in a single interaction from your JavaScript or iOS dapp
using [MetaMask SDK](../../concepts/sdk/index.md).
You can connect to MetaMask and sign data in a single interaction from your JavaScript, iOS,
Android, or Unity dapp using [MetaMask SDK](../../concepts/sdk/index.md).

The SDK's `connectAndSign` method provides a streamlined approach for dapps to interact with MetaMask.
This method combines the [`eth_requestAccounts`] and [`personal_sign`] RPC methods, executing them sequentially.
Expand All @@ -19,17 +19,20 @@ the output of [`eth_requestAccounts`] directly to [`personal_sign`].
This method enhances dapp user experience, especially on mobile platforms, by allowing users to
connect to MetaMask and sign a message in a single interaction, requiring only one switch between
the mobile dapp and MetaMask Mobile.
This is useful for various purposes such as authentication and transaction verification.

<p align="center">
<video width="350" controls>
<source src="/connect-and-sign.mp4" type="video/mp4" />
</video>
</p>

The following instructions describe how to connect and sign in JavaScript.
You can also see the [Unity instructions](../use-sdk/gaming/unity/connect-and-sign.md).

## Prerequisites

- MetaMask SDK set up in your [JavaScript](../use-sdk/javascript/index.md) or
[iOS](../use-sdk/mobile/ios.md) dapp.
- [MetaMask SDK set up](../use-sdk/javascript/index.md) in your JavaScript dapp.

- MetaMask Mobile version 7.10 or later.
Your users must have an updated version of MetaMask Mobile for this feature to work correctly.
Expand Down
50 changes: 50 additions & 0 deletions wallet/how-to/use-sdk/gaming/unity/connect-and-sign.md
@@ -0,0 +1,50 @@
---
sidebar_position: 1
sidebar_label: Connect and sign
tags:
- Unity SDK
---

# Connect and sign in Unity

You can [connect and sign](../../../sign-data/connect-and-sign.md) in a single interaction from your Unity game.

## Prerequisites

- [MetaMask SDK set up](index.md) in your Unity game.

- MetaMask Mobile version 7.10 or later.
Your users must have an updated version of MetaMask Mobile for this feature to work correctly.
For older versions of MetaMask, this function may not work as expected.

## Steps

1. Open your Unity project with the SDK installed.

2. In your script, create a new function named `ConnectAndSign`:

```csharp
public void ConnectAndSign()
{
MetaMaskUnity.Instance.ConnectAndSign("This is a test message");
}
```

Replace the test message with any string message you want to sign.

:::caution important
Make sure you initialize [`MetaMaskUnity.Instance`](../../../../reference/sdk-unity-api.md#instance)
before using this function.
To do so, enable **Initialize On Awake** in the **MetaMask Unity** script inspector, or run
[`MetaMask.Instance.Initialize()`](../../../../reference/sdk-unity-api.md#initialize).
:::

3. Call the `ConnectAndSign` function whenever you want to establish a connection and sign a message.
For example, you can call this function when a button is clicked:

```csharp
public void OnButtonClick()
{
ConnectAndSign();
}
```
6 changes: 6 additions & 0 deletions wallet/how-to/use-sdk/gaming/unity/index.md
Expand Up @@ -141,6 +141,11 @@ scene with its fields provided.
The transport field is also required if you want to use it isolated from the canvas that is spawned
by the transport, then it generates the QR code for you.

:::info Connect and sign
You can also [use the `connectAndSign` method](connect-and-sign.md) to
connect to MetaMask and sign data in a single interaction.
:::

### 5. Use MetaMask

Once the wallet is authorized, you can make requests to it.
Expand Down Expand Up @@ -261,6 +266,7 @@ The SDK is filled with precompiled libraries to save on runtime compilation.

Once you have the MetaMask Unity SDK set up, you can:

- [Connect and sign in Unity.](connect-and-sign.md)
- [Set up Infura in Unity.](infura.md)
- [Interact with smart contracts in Unity.](smart-contracts/index.md)
- [Enable human-readable addresses in Unity using Decentraweb.](dweb.md)