Skip to main content

Connecting accounts

Connecting to a user's wallet is a prerequisite to working with Tezos in any application. Accessing the wallet allows your project to see the tokens in it and to prompt the user to submit transactions, but it does not give your project direct control over the wallet. Users still confirm or reject all transactions in their wallet application, so you must handle both of these use cases.

Using a wallet application in this way saves you from having to implement payment processing and security in your application. Game developers can also use the wallet and its account as a unique account identifier and as the user's inventory.

For an example of connecting to wallets, see the WalletConnection tutorial scene.

Best practices

When working with wallets, be sure to follow the advice in Best practices and avoiding flaws for wallet connections. For example, don't force the user to connect their wallet as soon as the application loads. Instead, let them see the application first. Also, provide a prominent disconnect button to allow users to disconnect one account and connect a different one.

The TezosAuthenticator prefab

The TezosAuthenticator prefab provides the tools that you need to connect to user's Tezos wallets in a Unity project. You can copy the TezosAuthenticator and TezosManager prefabs to your scene, and the TezosAuthenticator prefab automatically adds features that connect to users' wallets.

Connection methods

This table shows the ways that the SDK can connect to wallets and which platforms they are appropriate for:

Connection methodDescriptionWeb platform (WebGL)Mobile appsStandalone applications
QR codeUsers scan a QR code with a wallet appYesNoYes
Deep linkThe application opens the user's wallet app directlyYesYesNo
Social walletsThe application opens the user's Kukai web-based walletYesNoNo

Regardless of the connection method, the Tezos Unity SDK runs the WalletConnected or WalletConnectionFailed event, as appropriate. For more information about events, see the Unity SDK EventManager object.

QR code connections

This method generates a QR code that a user scans with their wallet application:

  1. The Unity application calls the Wallet.Connect() method with the walletProvider parameter set to WalletProviderType.beacon to send a connection request to a wallet application via the TZIP-10 protocol.
  2. The wallet returns a handshake that includes pairing information for the wallet, which triggers the HandshakeReceived event.
  3. From the handshake information, the SDK generates a QR code. The TezosAuthenticator prefab handles the QR code generation with the QrCodeGenerator class.
  4. The user scans the QR code with their wallet app and approves the connection.
  5. The SDK receives the connection approval, which triggers the WalletConnected event and includes information about the connected account.

Deep link connections open the user's wallet app directly, which can be a mobile app or a browser extension. This method relies on the Beacon SDK to interact with wallet apps:

  1. The Unity WebGL application calls the Wallet.Connect() method with the walletProvider parameter set to WalletProviderType.beacon. The Beacon SDK detects that it is running in a web application and opens a popup window with the wallets that Beacon can connect to:

    Beacon popup window with wallet types including Temple and Umami
  2. The Beacon SDK handles the process of connecting to the wallet.

  3. The SDK receives the connection approval, which triggers the WalletConnected event and includes information about the connected account.

Social connections

Social wallets exist as accounts managed by web apps such as Kukai.

To connect to a social wallet, the Unity WebGL application calls Wallet.Connect() with the walletProvider parameter set to WalletProviderType.kukai.

Disconnecting

It's important to provide a disconnect button so the user can disconnect when they are finished with the application or if they want to connect with a different account. To disconnect the active wallet, call the Wallet.Disconnect() method.