Skip to content

Provides an easy way to interact with Web3 and possibility to work with contracts deployed on the blockchain

Notifications You must be signed in to change notification settings

ddocs/game-unity-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity SDK

The Ankr Unity SDK provides an easy way to interact with Web3 and to work with contracts deployed on the blockchain. As a plugin it easily integrates with MetaMask on Android and iOS.
View Demo

Table of Contents
  1. Install SDK
  2. What's in the SDK
  3. Getting Started
  4. Connect Web3 Wallet
  5. Perform Updates to NFTs
  6. Current ERC Proposals
  7. View Full Examples

🏗 Install SDK

  1. Download mirageSDK.unitypackage from the latest release.

  2. In your project, locate the 'Assets' folder. Move mirageSDK.unitypackage into this folder.

  3. 'Import all' to have access to all SDK capabilities.

👀 What's in the SDK

The SDK is designed to make it super easy to get started with Game development by enabling connection and interaction across different blockchains.

  • Contains a huge range of classes, plugins and example scripts for a variety of use cases.

  • Nethereum libraries provide support for web requests using RPC over Http.

  • Ankr RPC network infrastructure provides fast and easy connection to multiple chains.

Getting started

🧰 Prerequisites

  1. Smart Contracts must already be deployed on the blockchain. You have the Smart Contract addresses and ABI
  2. Web3.js or Ethers.js

📌 Use Cases

This help content focuses on the following use cases.

  1. Connecting to a Web3 Wallet (MetaMask) and Authenticating a user

  2. Performing Updates to NFTs by interacting with the blockchain and calling smart functions.

👝 01 Connect Web3 Wallet

Connecting to an Ethereum i.e. MetaMask wallet provides a link between a wallet address and a user's game account.

  1. Create an instance of a Web3 class and call Initialize method after successful login in metamask
string provider_url = "<ethereum node url>";
		
Web3 web3 = new Web3(provider_url);
web3.Initialize();
  1. Login via MetaMask is required to authenticate the user.
  • Call the SignMethod to trigger Signing via MetaMask.
string message = "Hi I am a message !"
string signature = await web3.Sign(message);
  • Continue by deploying the Unreal Engine (backend)

  • The backend returns a JSON object (payload) with the session_id and URI.

  • Web3.Sign(string) returns the signature.

  1. Verify the user account and address as follows:
POST `/account/verification/address`

The body contains a message and the signature returned from Web3.sign().

{
  "message": "Hi I am a message !", // your message
  "signature":"0x..." // result of Web3.Sign()
}

It returns the address of the user from their signature so it can be written to database as follows:

...
sigPublicKey := getAddrFromSign(input.Signature, data)
address := string(sigPublicKey);
// add address to a database
...

Inside MirageSDK/Examples/UseCases/LinkingAccountWalletis an example script demonstrating how to link a crypto wallet (MetaMask) to a player account.

🚀 02 Perform Updates to NFTs

Making updates to the NFT e.g. adding a red hat to a character requires signing and sending a transaction.

Signing Transactions

All updates are transactions that must be signed via a prompt from MetaMask.

Sending Transactions

There are two ways to make update transactions. Using the GetData method and the CallMethod

GetData Method

Use the GetData method to retrieve information from the blockchain. (READ functions do NOT require mining.). Other non-standard Get functions are also available

These methods require

  • Contract Address
  • ABI

The following extract is an example usage of the GetData method to retrive information about an NFT:

private async UniTask<BigInteger> GetHat(BigInteger tokenID)
		{
			var getHatMessage = new GetHatMessage
			{
				CharacterId = tokenID.ToString()
			};
			var hatId = await _gameCharacterContract.GetData<GetHatMessage, BigInteger>(getHatMessage);

			UpdateUILogs($"Hat Id: {hatId}");

			return hatId;
		}

CallMethod

Use the CallMethod to write new information to the blockchain. These methods utilize gas.

The following extract is an example of how a CallMethod is used to update an NFT:

public async void UpdateNFT()
		{
			// 1) Request nft parameters and signature for parameters
			var info = await RequestPreparedParams(0);
			// 2) Call method that check signature and update nft
			var receipt = await _contract.CallMethod("updateTokenWithSignedMessage", new object[] { info });

			Debug.Log($"Receipt: {receipt}");
		}

🗒 Current ERC Proposals

We have two ERC proposals.
ERC-4884 Rentable NFT Standard ERC-4911 Composability Extension For ERC-721 Standard

(back to top)

View Full Examples

For full examples:

View ERC20 token example and ERC721 token example

About

Provides an easy way to interact with Web3 and possibility to work with contracts deployed on the blockchain

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.8%
  • ShaderLab 1.9%
  • Other 0.3%