Tezos SDK for Unity
The Tezos SDK for Unity offers a comprehensive toolkit designed to facilitate Web3 gaming development. This SDK provides game developers with the necessary tools to:
- Connect to a Tezos wallet: Enable user authentication, transaction signing, on-chain asset access, and cryptocurrency usage for in-game purchases.
- Access blockchain data: Retrieve data from the Tezos blockchain, like in-game asset ownership. Manage asset storage through smart contracts or off-chain views, accessing blockchain-stored data.
- Invoke smart contracts: Generate calls to Tezos smart contracts, allowing user-signed transactions for purchasing features or creating achievement-based in-game assets.
- Establish true ownership of in-game assets: Enable users to own and verify in-game assets' authenticity via the Tezos blockchain, using smart contracts for data validation.
Get Started
Begin by watching our Getting Started video.
This Getting Started guide covers the following five steps essential for using the Tezos SDK in your Unity game or app development:
- Installation of the Unity Editor (if not already installed)
- Installation of the Tezos Integration SDK in the Unity Editor within a new project
- Obtaining a Tezos-compatible wallet as an app or browser plugin (we'll use the Temple wallet for our Inventory Sample Game)
- Creating a wallet account for a test network (
ghostnet
) and acquiring test currency from an appropriate faucet - Linking this wallet account with the new Unity project
By following these steps, your Unity app will be connected to the Tezos GhostNet test network via your specific wallet address. This allows you to invoke specific functionality on smart contracts you've created and deployed to GhostNet, as demonstrated in our Inventory Sample Game.
Explore the Inventory Sample Game project and consult our API Documentation to learn more about the exposed methods of our SDK, both for establishing wallet connections and for calling specific smart-contract entrypoints and Tezos data-view functions.
This SDK documentation is designed for users with some familiarity with Unity game development but may have little to no experience with Web3 or Tezos blockchain. If you're well-versed in both domains, you might want to skip "Getting Started" and proceed directly to the API documentation. Nonetheless, the Inventory Sample Game can still be valuable for visualizing potential SDK applications in your own game development.
Installing the Unity Editor
- Install Unity Editor version 2021.3.13 or above
- Enable iOS Build Support, even if you don't plan to build for iOS
The Tezos SDK has been developed and tested primarily in Unity 2021.3.13. If you're using an earlier version, you must install version 2021.3.13 or above.
Newer Unity versions can coexist with older ones, allowing you to maintain older games built in previous editor versions. Manage different Unity installations through the Installs tab of your Unity Hub. This tool helps you track installations, projects, and required modules for publishing games or dApps to platforms like Windows, iOS, Android, WebGL, and others.
If you're new to Unity, download the Unity editor for free. The free "personal" Unity editor offers a comprehensive core feature set for creating 2D and 3D games, apps, and environments, including AR, VR, and Web3 development.
The current SDK version requires iOS Build Support, even if you don't plan to build for iOS. This will be fixed in a future update. In the meantime, enable iOS Build Support in the "Installs" tab of your Unity Hub.
Installing the Tezos SDK for Unity (Latest)
Install from a Git URL
You can install the UPM package directly from a Git URL. To do this:
- Open the Unity Package Manager window.
- Click the add + button in the status bar.
- Select Add package from git URL from the add menu. A text box and an Add button will appear.
- Enter the
https://github.com/trilitech/tezos-unity-sdk.git
Git URL in the text box and click Add. - You can also install a specific package version using the URL with the specified version:
https://github.com/trilitech/tezos-unity-sdk.git#X.Y.Z
- Replace
X.Y.Z
with the version you want to install. - Check all available releases here.
- The latest available release version is:
For more information about supported protocols, see Git URLs.
Install from NPM
-
Navigate to your project's
Packages
directory. -
Edit the project manifest file
manifest.json
in a text editor. -
Ensure
https://registry.npmjs.org/
is part ofscopedRegistries
.-
Make sure
com.trilitech
is included inscopes
. -
Add
com.trilitech.tezos-unity-sdk
to thedependencies
, specifying the latest version. -
A minimal example looks like this. Replace
X.Y.Z
with the latest released version, which is currently:
{
"scopedRegistries": [
{
"name": "npmjs",
"url": "https://registry.npmjs.org/",
"scopes": [
"com.trilitech"
]
}
],
"dependencies": {
"com.trilitech.tezos-unity-sdk": "X.Y.Z",
...
}
} -
-
Return to the Unity Editor and wait for it to finish importing the added package.
WebGL Support
- Open Unity Editor.
- Navigate to Project -> Packages and find the Tezos Unity SDK.
- Double-click the package file WebGLSupport.unitypackage. Project->Packages->Tezos-Unity-SDK.
- The Import Unity Package dialog box displays, with all the items in the package pre-checked, ready to install.
- This action creates WebGL template folders in your Project. Each template is a subfolder within the WebGLTemplates folder. Each template subfolder contains an index.html file along with any other resources the page needs, such as images or stylesheets.
API Summary
The SDK's API includes seven methods, which, together with the BeaconSDK and Netezos libraries, provide comprehensive access to the Tezos Blockchain for your games:
- ConnectWallet: Handles wallet pairings using QRCode scans, deep links, or injections, depending on the platform. Supports various Tezos wallets such as Kukai, Umami, or Temple.
- DisconnectWallet: Disconnects the app from the user's wallet.
- GetActiveWalletAddress: Retrieves the Tezos address of the currently active wallet account.
- ReadBalance: Returns the tez balance of the current user.
- ReadView: Calls an off-chain view to obtain data from a smart contract and its storage.
- CallContract: Enables calls to any Tezos contract by specifying the entrypoint, input parameters, and tez amount sent to the contract.
- RequestSignPayload: Requests the user to digitally sign data with their wallet.
Additional features and data retrieval options from the Netezos SDK are included in this SDK.
Dependencies
The Tezos SDK utilizes modified versions of the following libraries for communication:
- Airgap Beacon SDK: Interacts with Tezos wallets through the Beacon standard for iOS, Android, and WebGL platforms.
- Netezos: Interacts with Tezos wallets through the Beacon standard for Windows, Linux, and MacOS platforms. Also prepares parameters for smart contract calls and interprets complex data returned by the ReadView method.
Supported Platforms
The SDK supports Windows, Linux, MacOS, iOS, Android, and WebGL platforms.
For more information you can read detailed documentation on OpenTezos.