As an example of using the Immutable Unity SDK, we'll use a Unity game called “Immutable Runner”, a customised version based on the Unity Runner game template. In this game, the player takes on the role of an adventurous fox who must collect Immutable coins and food while avoiding obstacles like trees and bears to reach the finish line.
What makes this game unique is that the Fox, Skins and Immutable Runner coins will be represented as NFTs (ERC721). This means that players can own these digital assets. Moreover, players can use the Immutable Runner coins they have collected to create or craft new skins for their fox. These skins will also be represented as NFTs, further enriching the player's ownership experience.
- Windows
- Android
- iOS
- macOS
Some files are stored on Git Large File Storage, so you must download and install git-lfs from here.
Important
This game is set up to work on the Testnet/Sandbox environment only
- Register the game by following the Immutable X or Immutable zkEVM guide
- Make sure to set the Redirect URLs field to
imxsample://callback
- Make sure to set the Logout URLs field to
imxsample://callback/logout
- Make sure to set the Redirect URLs field to
- Open
Assets/Runner/Scripts/Config.cs
and set the client ID
To support minting and crafting in the game, three NFT collections need to be present:
- Immutable Runner Token (IMR) for the Immutable coins you see in the game
- Immutabler Runner Character (IMRC) for the Fox Runner character you use to play the game
- Immutable Runner Skin (IMRS) for any skin you manage to unlock and claim
- Set up your development wallet
- Obtain Test-$IMX so you can send transactions (specifically to mint assets in this game) and deploy smart contracts on zkEVM Testnet
- Follow this to deploy the three zkEVM contracts the game requires
- Rename
server/.env.example
to.env
:- Update
PRIVATE_KEY
with your admin wallet's private key - Update
ZK_TOKEN_TOKEN_ADDRESS
to the contract address of Immutable Runner Token - Update
ZK_CHARACTER_TOKEN_ADDRESS
to the contract address of Immutable Character Token - Update
ZK_SKIN_TOKEN_ADDRESS
to the contract address of Immutable Skin Token - Update
ALCHEMY_API_KEY
with your Alchemy Sepolia API key
- Update
- Open
Assets/Runner/Scripts/Config.cs
- Update
ZK_TOKEN_TOKEN_ADDRESS
to the contract address of Immutable Runner Token - Update
ZK_SKIN_TOKEN_ADDRESS
to the contract address of Immutable Skin Token
- Update
- The game uses zkEVM Send Transactions to perform crafting, so you must contact us for pre-approval. You will need to provide us:
- The name of the game
- The environment i.e. Testnet
- The client ID
- The
ZK_TOKEN_TOKEN_ADDRESS
and the function signature of the craftSkin method, i.e.0x63daf310
- Follow this guide on how to create the three NFT collections
- Rename
server/.env.example
to.env
:- Update
PRIVATE_KEY
with your wallet's private key - Update
TOKEN_TOKEN_ADDRESS
to the contract address of Immutable Runner Token - Update
CHARACTER_TOKEN_ADDRESS
to the contract address of Immutable Character Token - Update
SKIN_TOKEN_ADDRESS
to the contract address of Immutable Skin Token - Update
ALCHEMY_API_KEY
with your Alchemy Sepolia API key
- Update
- Open
Assets/Runner/Scripts/Config.cs
- Update
TOKEN_TOKEN_ADDRESS
to the contract address of Immutable Runner Token - Update
SKIN_TOKEN_ADDRESS
to the contract address of Immutable Skin Token
- Update
- The game uses Immutable X Single and Bulk transfer to perform crafting, so you must contact us for pre-approval. You will need to provide us:
- The name of the game
- The environment i.e. Sandbox
- The client ID
- The
TOKEN_TOKEN_ADDRESS
and the receiver's address0x0000000000000000000000000000000000000000
Run the server once pre-approved to use Immutable X Single/Bulk transfer and/or zkEVM Send Transactions for crafting.
The local server is used to mint and help craft assets.
- Navigate to
server/
- Run
npm install
- Run
npm run build
- Run
npm run dev
- Switch to the platform you would like to run on in Build Settings
- Start the game
- If you are running the game inside the Editor, open
Assets/Shared/Scenes/Boot.unity
- If you are running the game inside the Editor, open
Run the server once pre-approved to use Immutable X Single/Bulk transfer and/or zkEVM Send Transactions for crafting.
The local server is used to mint and help craft assets.
- Grab your local IP address
- On Mac (Ethernet connection): Enter
ipconfig getifaddr en1
in your terminal - On Mac (Wireless connection): Enter
ipconfig getifaddr en0
in your terminal - On Windows: Enter
ipconfig
in command prompt -> grab the IPv4 Address
- On Mac (Ethernet connection): Enter
- Open
Assets/Runner/Scripts/Config.cs
- Update the
SERVER_BASE_URL
to your local IP address including the scheme (http://
) and the port number (6060
), e.g.http://192.168.0.123:6060
- Navigate to
server/
- Run
npm install
- Run
npm run dev
- Switch to the platform you would like to run on in Build Settings
- Start the game
- If you are running the game inside the Editor, open
Assets/Shared/Scenes/Boot.unity
- If you are running the game inside the Editor, open
On the main menu screen, there is a small checkbox at the top right that toggles between Immutable X and zkEVM. If checked, zkEVM will be used.
This flag is also saved in the game's SaveManager
.
The local server is used to mint assets the gamer collects directly to their wallet. See endpoints /mint/*
for Immutable X and zkmint/*
for zkEVM.
Crafting is done by calling the craft function in the smart contract. This is done by using zkEVM Send Transaction.
For example, to claim the cooler skin, the user needs to burn their current skin first:
- Get the encoded data required to call the RunnerSkin contract's
craftSkin
function by callingPOST /zk/skin/craftskin/encodeddata
- Use zkEVM Send Transaction to call the
craftSkin
function by passing the RunnerSkin contract address and the encoded data- Note that the craftSkin function does all the burning and minting
Crafting is done by using the Immutable X Single and Bulk transfer functions.
Required asset(s) to craft a new asset is transferred to 0x0000000000000000000000000000000000000000
to burn them. Once that is successful, the new asset is minted to the gamer's wallet using the local server.
For example, to claim the first skin, the user needs to burn three of their tokens:
- Burn three tokens using Immutable X Bulk Transfer
- Mint skin using the
POST /mint/skin