Skip to content

fivebinaries/cardano-unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cardano games assets for Unity

This repository contains the code and configuration files of Cardano game assets for Unity.

It is a lighthweight Unity-specific client for interacting with blockfrost.io API. It's built on UniTask for allocation-free async operations and uses Unity's native HTTP client (UnityWebRequest) and JSON parser (JsonUtility).

InstallationCardanoMilkomedaDemo



Installation

Unity Asset Store

We're going to publish this package to the Asset Story in the near future.

Package Manager

Client can be installed using Unity Package Manager using git.

  • Go to Package Manager, select Add package from git URL...
  • Enter https://github.com/fivebinaries/cardano-unity.git?path=src/Blockfrost.io

NOTE: Dependancy has to be installed manually if they are missing, see Installing UniTask.

Manual installation

You can copy Blockfrost.io folder into your project. Installing dependancy is required.

Cardano API

Getting started

  1. Get your own PROJECT_ID from blockfrost.io
  2. Create configuration CreateBlockfrost.io APIConfiguration and fill in the PROJECT_ID
  3. In your MonoBehaviour create new instance of Blockfrost.Cardano by passing in reference to your configuration
  4. You can now call the API and access the Cardano blockchain

Example

var config = new Blockfrost.Configuration{
  ProjectID = myProjectID;
};

var client = Blockfrost.Cardano(config);
var latestBlock = await client.GetLatestBlock();

Debug.Log(response.hash);

Listing

Some endpoints allow certain listing operations (number of items in a list, order, .etc). There are three filters available Blockfrost.Listing, Blockfrost.OrderedListing, and Blockfrost.TargetableOrderedListing that can be passed to specific methods.

api.GetBlockTransactions(hash, new Listing{count = 10})

Errors

Handle original errors from UnityWebRequest.

Milkomeda API

To use Milkomeda API follow steps in Cardano section, but select Milkomeda in your Blockfrost API configuration. The client currently only supports raw json messages on both input and output.

var client = Blockfrost.Milkomeda();

var data = @"{""jsonrpc"": ""2.0"", ""method"": ""net_version"", ""params"": [], ""id"": 1}";
var response = await client.RPC(data);

Debug.Log(response);

Demo

Demo using Nami wallet can be found here and its sources here. In this simple game, the door won't open until your wallet contains a specific NFT.