Skip to content

Reddio Unity SDK

Zhou Zhiqiang edited this page Dec 6, 2022 · 7 revisions

Introduction

Reddio Unity SDK provides unity CSharp scripts for using Reddio API, in async/await pattern or Unity Coroutine pattern.

Getting Started

1. Import Reddio Unity SDK and dependencies.

  • Reddio Unity SDK requires UniTask for providing APIs in Unity Coroutine style, you can download UniTask from here
  • Download the latest version of Reddio Unity SDK here.
  • Optional: If you want to interact with the wallet application (eg. MetaMask), you should install WalletConnect by following these instructions

After setup these packages for your Unity project, you can write scripts for your application with Reddio API.

2. Example: Write a script to query the user's balances with stark_key

With async/await:

public async void GetBalance()
{
    var reddioRestClient = ReddioRestClient.Testnet();
    var balance = await reddioRestClient.GetBalance(
        new GetBalanceMessage("0x1c2847406b96310a32c379536374ec034b732633e8675860f20f4141e701ff4", ""));
    Debug.Log("balance: " + balance);
}

Or with Unity Coroutine:

public void OnClick()
{
    StartCoroutine(GetBalance());
}

public IEnumerator GetBalance()
{
    var reddioRestClient = ReddioRestClient.Testnet();
    var unityClient = new ReddioUnityRestClient(reddioRestClient);

    yield return unityClient.GetBalance(
        new GetBalanceMessage("0x1c2847406b96310a32c379536374ec034b732633e8675860f20f4141e701ff4", ""),
        (balance) =>
        {
            Debug.Log("balance: " + balance);
            // your codes here
        },
        (error) => { // resolve the exception });
}

Well-known Classes and Methods

Low-Level API: IReddioRestClient and ReddioRestClient

IReddioRestClient is the interface of Low-Level API for using Reddio API, you could find the corresponding methods for each rest API.

ReddioRestClient is the implementation of Low-Level Rest API, and there are two factory methods for instantiating: ReddioRestClient.mainnet() and ReddioRestClient.testnet().

High-Level API: IReddioClient and ReddioClient

IReddioClient is the interface for High-Level API. It encapsulates the complex and boring codes for signing the request with StarEx Cryptographic Library for easy-to-use purposes.

The default implementation is ReddioClient.

We recommend using High-Level API for a better experience.

StarEx Cryptographic Library: CryptoService

CryptoService provides interaction with StarEx Cryptographic, like Signing and Public-key cryptography related methods.

Available Features

  • StarEx Cryptographic Library
  • Low-Level and High-Level Reddio API client.