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
).
Installation • Cardano • Milkomeda • Demo
We're going to publish this package to the Asset Story in the near future.
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.
You can copy Blockfrost.io folder into your project. Installing dependancy is required.
- Get your own
PROJECT_ID
from blockfrost.io - Create configuration Create → Blockfrost.io API → Configuration and fill in the
PROJECT_ID
- In your MonoBehaviour create new instance of Blockfrost.Cardano by passing in reference to your configuration
- You can now call the API and access the Cardano blockchain
var config = new Blockfrost.Configuration{
ProjectID = myProjectID;
};
var client = Blockfrost.Cardano(config);
var latestBlock = await client.GetLatestBlock();
Debug.Log(response.hash);
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})
Handle original errors from UnityWebRequest
.
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 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.