Skip to content

All API Methods

Chain of Industry edited this page Jun 28, 2022 · 11 revisions

API Methods

All API methods are static and are available inside Manager.cs


Connect

This is required before making any blockchain transaction. It is used to initialize the WalletConnect socket used for Maiar connection.

/// <param name="OnWalletConnected">Callback triggered when user wallet connected</param>
/// <param name="OnWalletDisconnected">Callback triggered when user wallet disconnected</param>
/// <param name="qrImage">The image component that will display the QR for Maiar login</param>
public static void Connect(UnityAction<AccountDto> OnWalletConnected, UnityAction OnWalletDisconnected, Image qrImage)

Usage example:

//method call
ElrondUnityTools.Manager.Connect(OnConnected, OnDisconnected, qrImage);

private void OnConnected(AccountDto connectedAccount)
{
    //do actions with the connected wallet
}

private void OnDisconnected()
{
    //do actions when wallet disconected from the app
}

Is Wallet Connected

Simple check for connection status

/// <returns>true - if connection to the wallet is active</returns>
public static bool IsWalletConnected()

Usage example:

//method call
if (ElrondUnityTools.Manager.IsWalletConnected() == true)
{
    //do something if connection is active
}

Deep Link Login

Login from the same mobile device that has the Maiar app already installed. It will automatically open the Maiar app. The Connect method must be called first.

public static void DeepLinkLogin()

Usage example:

ElrondUnityTools.Manager.DeepLinkLogin();

Send Transaction

Send an EGLD transaction for signing to the Maiar wallet. After the signing the transaction will be automatically broadcasted to the blockchain.

/// <param name="destinationAddress">The erd address of the receiver</param>
/// <param name="amount">Amount of EGLD to send(in decimals)</param>
/// <param name="data">An optional custom message</param>
/// <param name="TransactionStatus">Callback to track the status of the transaction. At complete, the message will be the transaction hash</param>
public static void SendTransaction(string destinationAddress, string amount, string data, UnityAction<OperationStatus, string> TransactionStatus)

Usage example:

//Method call
ElrondUnityTools.Manager.SendTransaction("erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf", "0.001", "You see this?", SigningStatusListener);

/// <summary>
/// Track the status of the signing transaction
/// </summary>
/// <param name="operationStatus"></param>
/// <param name="message">if the operation status is complete, the message is the txHash</param>
private void SigningStatusListener(ElrondUnityTools.OperationStatus operationStatus, string message)
{
    if (operationStatus == ElrondUnityTools.OperationStatus.Complete)
    {
        //save transaction hash
        //txHash = message;
        //check transaction status
    }
}

Check Transaction Status

Check the status of a specific transaction (it is processed or not by the blockchain)

/// <param name="txHash">The hash of the transaction obtained after signing</param>
/// <param name="TransactionStatus">Callback to track the result</param>
/// <param name="delay">Time to wait before querying the tx status. A tx takes some time to process so some delays are good to limit the usage of the APIs</param>
public static void CheckTransactionStatus(string txHash, UnityAction<OperationStatus, string> TransactionStatus, float delay)

Usage example:

//Method call
ElrondUnityTools.Manager.CheckTransactionStatus(txHash, BlockchainTransactionListener, 1);

private void BlockchainTransactionListener(ElrondUnityTools.OperationStatus operationStatus, string message)
{
    if (operationStatus == ElrondUnityTools.OperationStatus.Complete)
    {
        if (message == "pending")
        {
            //check again later
            ElrondUnityTools.Manager.CheckTransactionStatus(txHash, BlockchainTransactionListener, 1);
        }
        else
        {
            if (message == "success")
            {
                //refresh account
            }
         }
    }
}

Disconnect

Close the connection with the wallet

public static void Disconnect()

Usage example:

ElrondUnityTools.Manager.Disconnect();
Clone this wiki locally