Quick Start Guide
WalletConnect is a powerful protocol that allows you to connect your Unity game with various mobile wallet-supported decentralized applications (dApps) on the blockchain. This integration enables players to interact with blockchain assets, perform transactions, and access various blockchain features within your game. In this documentation, we will guide you through the process of integrating WalletConnect into your Unity project.
Prerequisites
Before you get started with WalletConnect in Unity, make sure you have the following prerequisites in place:
-
Unity: Ensure that you have Unity installed on your development machine. You can download Unity from the official Unity website.
-
Eidolon.Unity SDK: You can obtain the Eidolon.Unity SDK package by clicking here. The SDK package contains all the necessary components to get started with blockchain integration in your Unity project.
Getting Started
1. Configure Your Wallet
In order to use WalletConnect within your Unity project, you first need to configure it. Luckily we’ve made this extremely easy through our Wallet Connect
editor tool found directly under Eidolon
in your Unity editor!
- After downloading the extension package, drag and drop it anywhere in your Unity assets to import the files.
- At the top of your editor, click on
Ēidolon
and then onWallet Connect
. This should open the window you see below.
In here you’ll be able to configure the following:
Project ID
- This is your Wallet Connect Project ID which can created on their official website.App Description
- Your project Description.App Name
- Your project Name.App URL
(optional) - Your Project URL. Wallet Connect can use it for added authentication.
After filling our the required fields and saving your configuration, you’ll be ready to use wallet connect in your Unity project.
Next, let’s look at some example Usage:
2. Connect Players To Your Game
WalletConnect allows mobile wallet dApps to connect players to your Unity game, you can achieve this by doing the following:
-
Create a new Unity C# script for use in your game scene.
-
Declare new
WalletConnectWallet
andRawImage
variables. -
Next, let’s instantiate an instance of our wallet for use in-game.
-
After we’ve instantiated our wallet, we can generate a new QR code for players to scan and connect to. Players can scan this QR code to connect their preferred mobile wallets to the current game session.
A new QR code should render on your
RawImage
. You can use your phone to connect to the game through any Wallet Connect enabled wallet; likeTrust Wallet
orMetaMask Mobile
.
-
Create a new Unity C# script for use in your game scene.
-
Declare a new
WalletConnectWallet
variable. -
Next, let’s instantiate an instance of our wallet for use in-game.
-
After we’ve instantiated our wallet, we can create the logic required to connect a user to our mobile game. You can use a button, or invoke the below at any point where you need it.
3. Send a Transaction
Now that we have a connection between our wallet and the game, let’s have a look at how Wallet Connect ties into the Smart Contract class to send transactions.
4. Sign a message
If you need a player to sign a message, you can send a request to their wallet using the below:
5. Disconnect a Player
Once the session is done or you’d like to disconnect your player, you can simply do the below:
Conclusion
WalletConnect integration in Unity opens up a world of possibilities for your game by allowing players to interact with blockchain assets and dApps seamlessly. By following this documentation and referring to the example scene built into the package, you should be able to your game blockchain ready in no time!
Happy developing!