NAV

Introduction

Desonity is a Package for Unity Game Engine that allows game developers to integrate the DeSo Blockchain into their games.

With Desonity, one can implement features such as NFTs, Creator Coins, DAO Coins, and Social aspects of the Deso Blockchain into their games.

Installation

That's it! You've imported Desonity in your project

Using Desonity

Since Desonity uses API calls to interact with the DeSo Blockchain, you must use its methods within an async method.

using UnityEngine;
using Desonity;

public class ExampleCLass : MonoBehaviour
{
    // Start() is an Async function
    async void Start()
    {
        // Do something with Desonity
    }
}

To use Desonity you add the Desonity namespace to your script files.

By default various Unity specific functions such as Start() donot support Async/Await methods. To get around this Desonity uses Async Await Support Asset which can be found in Desonity/Runtime/Plugins folder.

Identity Login

Setting up the backend

In order to use Identity Login you need to setup a backend with which Unity will interact and open the web browser where the user can login, the logged in Public Key will be returned to the script which called the login function.

A Python Flask example is available in Desonity/Backend-Flask repository. You can host this on a paid VPS or use a free service such as Heroku or Repl.it.

A flask app is already hosted on https://desonity-login.herokuapp.com which you can use for testing purposes. (Not reccomended for production use as uptime cannot be guaranteed)

Login with Identity

Create an Identity object using Desonity.Identity().

This will open the default browser and prompt the user to login with a DeSo account.

async void Start()
{
    string appName = "Docs-App-Demo";
    string backendUrl = "https://desonity-login.herokuapp.com";

    var user = Desonity.Identity();
    user.setLoginURL(backendUrl, appName);

    await user.Login();
}

Optionally you can also pass a DeSo public key and perform actions using that.

async void Start()
{
    string myPublicKey = "BC1YLhF5DHfgqM7rwYK8PVnfKDmMXyVeQqJyeJ8YGsmbVb14qTm123G";
    var user = Desonity.Identity(myPublicKey);
}
Parameters Description
appName Name of the app that will be shown to users during Login.
backendUrl Url for the backend which will handle Login.
PublicKeyBase58Check Public Key of a DeSo Profile (optional).
seedHex Seed Hex of the passed Public Key (optional).

Transactions

Txn Generation and Submission

Every successfull transaction on deso consists of the following steps:

  1. We make a post request to a deso endpoint, endpoint returns a transaction hex.
  2. We use the users seed hex and sign the transaction hex.
  3. We call another endpoint and submit the signed transaction hex.
  4. If everything went well, the transaction is successfull and will be synced with all nodes.

Getting the Seed Hex

To be able to create a post using Desonity you will need the Seed Hex of the Public Key you are going to make the post from.

The Seed Hex is a sensitive Token that only the owner of the Public Key should have.

async void Start()
{
    string myPublicKey = "BC1YLhF5DHfgqM7rwYK8PVnfKDmMXyVeQqJyeJ8YGsmbVb14qTm123G";
    string mySeedHex = "NEVER GONNA GIVE YOU UP, NEVER GONNA LET YOU DOWN"; // Fake SeedHex

    var user = Desonity.Identity(myPublicKey, mySeedHex);
}

To get your Seed Hex, visit any website where you logged in with deso identity and open the developer console. Navigate to the Application tab and find identity.deso.org under local storage. From there find the Users item and copy the seed hex from your public key.

Once you get your seed, you can create an Identity object and pass the public key along with its seed hex. This identity object can now be used to sign transactions

Using Desonity functions

To interact with deso APIs, you must first create an object that contains the necessasary data that will be needed by the endpoint.

To do so, you must use the Desonity.Endpoints namespace in you C# script. This namespace contains all the classes for any endpoint implemented within Desonity. The endpoint object can then be passed into an appropriate function for processing.

For example, when you want to get the posts created by a public key, you must use the GetPostsForPublicKey class to create an object

using Desonity;
using Desonity.Endpoints;
...

async void Start()
{
    // This payload will be later used in other funtions
    var payload = new GetPostsForPublicKey{
            Username = "weeblet",
            NumToFetch = 10,
            MediaRequired = true,
            ...
    }
}

Once the post request has been done and (if) the API has returned some data, you will need to use one of the classes from Desonity.Objects namespace to store the returned data in an object of the appropriate class.

Continuing the above example, we will call Desonity.Posts.getPostsForPublicKey() and pass the payload we created earlier.

using Desonity;
using Desonity.Endpoints;
using Desonirt.Objects;
...

async void Start()
{
    var payload = ...;
    PostsList usersPosts = Posts.getPostsForPublicKey(payload);
    // getPostsForPublicKey has a return type PostsList,
    // which contains a List object of type PostEntry
}

Summing it wup!

Posts

All functions relating to posts can be found under Desonity.Posts

Users

All functions relating to users can be found under Desonity.Users

NFTs

All functions relating to NFTs can be found under Desonity.Nft