Skip to content

Commit

Permalink
Merge branch 'main' into 1165-keyring-reference
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandratran committed Feb 26, 2024
2 parents 0121057 + 1831065 commit 442801c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions snaps/features/custom-evm-accounts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ See the following example account management Snap implementations:

- [Simple Account Snap](https://github.com/MetaMask/snap-simple-keyring)
- [Simple Account Abstraction Snap](https://github.com/MetaMask/snap-account-abstraction-keyring/tree/main) (ERC-4337)
- [Biconomy Smart Account Snap](https://github.com/bcnmy/smart-account-keyring-template) (ERC-4337)
- [Silent Shard Snap](https://github.com/silence-laboratories/silent-shard-snap)
- [Safeheron MPC Snap](https://github.com/Safeheron/multi-mpc-snap-monorepo)
- [Capsule Keyring Snap](https://github.com/capsule-org/mm-snap-keyring)
11 changes: 7 additions & 4 deletions wallet/how-to/sign-data/connect-and-sign.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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)

0 comments on commit 442801c

Please sign in to comment.