Skip to content

All API Methods

Chain of Industry edited this page Aug 18, 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 EGLD 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
    }
}

Send ESDT Transaction

Send an ESDT 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="token">Token to send</param>
/// <param name="amount">Amount of token to send(in decimals)</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 SendESDTTransaction(string destinationAddress, ESDTToken token, string amount, UnityAction<OperationStatus, string> TransactionStatus)

Usage example:

//Method call
ElrondUnityTools.Manager.SendESDTTransaction("erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf",ElrondUnityTools.SupportedESDTTokens.USDC, "0.1", 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
    }
}

Load wallet NFTs

Load metadata from all NFT properties from the connected wallet. From the metadata the media files can be downloaded

/// <param name="LoadNFTsComplete">Callback triggered on load finish. Receives the metadata for each NFT as parameter</param>
public static void LoadWalletNFTs(UnityAction<OperationStatus, string, NFTMetadata[]> LoadNFTsComplete)

Usage example:

//Method call
ElrondUnityTools.Manager.LoadWalletNFTs(LoadNFTComplete);

/// <summary>
/// Listener triggered when NFT metadata is loaded
/// </summary>
/// <param name="operationStatus">Completed, In progress or Error</param>
/// <param name="message">additional message</param>
/// <param name="allNfts">All metadata properties serialized as NFTMetadata type</param>
private void LoadNFTComplete(ElrondUnityTools.OperationStatus operationStatus, string message, ElrondUnityTools.NFTMetadata[] allNfts)
{
      if (operationStatus == ElrondUnityTools.OperationStatus.Complete)
      {
            //after all metadata is loaded display the NFTs
            for (int i = 0; i < allNfts.Length; i++)
            {
                  DisplayNft(allNfts[i]);
            }
      }
      else
      {
            Debug.Log(operationStatus + " " + message);
      }
}

Send NFT Transaction

Send an NFT to the destination address. After the signing the transaction will be automatically broadcasted to the blockchain.

/// <param name="destinationAddress">the address to send the NFT to</param>
/// <param name="collectionIdentifier">the collection ID</param>
/// <param name="nftNonce">nonce of the NFT, you can get it from metadata</param>
/// <param name="quantity">number of units to send</param>
/// <param name="TransactionStatus">Callback to check the transaction status</param>
public static void SendNFT(string destinationAddress, string collectionIdentifier, int nftNonce, int quantity, UnityAction<OperationStatus, string> TransactionStatus)

Usage example:

//Method call
ElrondUnityTools.Manager.SendNFT("erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf", "ADT-8daf0d", 3560, 1, CompleteListener);

/// <summary>
/// Track the status of the send NFT transaction
/// </summary>
/// <param name="operationStatus">Completed, In progress or Error</param>
/// <param name="message">if the operation status is complete, the message is the txHash</param>
private void CompleteListener(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