-
Notifications
You must be signed in to change notification settings - Fork 3
Send ESDT Transaction
This section shows you how to send an ESDT token transaction to the Maiar app for signing and broadcasting it on the blockchain. To be able to send transactions, a user needs to be already connected. See the Connect Maiar section on how to connect the user wallet.
To be able to send an ESDT token, first, a token needs to be defined like below:
Create a static variable of type Token and pass your token parameters inside the constructor.
public class SupportedESDTTokens
{
public static Token USDC = new Token("USDC", "USDC-8d4068", 6);
public static Token WEB = new Token("WEB", "WEB-5d08be", 18);
}
The constructor parameters are the following:
/// <summary>
/// ESDT Constructor
/// </summary>
/// <param name="name">Name of ESDT toke, used only for display purpose</param>
/// <param name="ticker">The identifier as used on blockchain(Name+numeric value)</param>
/// <param name="decimalPrecision">number of decimals</param>
public ESDTToken(string name, string ticker, int decimalPrecision)
The parameters can be found inside Elrond Explorer:
To send an ESDT transaction, this API method is used:
/// <summary>
/// Send an ESDT transaction for signing to the Maiar wallet. After the signing the transaction will be automatically broadcasted to the blockchain
/// </summary>
/// <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, Token token, string amount, UnityAction<OperationStatus, string> TransactionStatus)
To be more clear, here is a usage example:
private string defaultAddress = "erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf"; //address to send the transaction
private double USDCValue = 0.001;
//method connected to a button
public void SendTransaction()
{
MultiversXUnityTools.Manager.SendESDTTransaction(defaultAddress, MultiversXUnityTools.SupportedESDTTokens.USDC, USDCValue.ToString(), 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(MultiversXUnityTools.OperationStatus operationStatus, string message)
{
if (operationStatus == MultiversXUnityTools.OperationStatus.Complete)
{
// store the transaction hash for later use
txHash = message;
//check the status of the transaction. More details in Check Transaction Status section
MultiversXUnityTools.Manager.CheckTransactionStatus(txHash, BlockchainTransactionListener, 6);
}
if (operationStatus == MultiversXUnityTools.OperationStatus.Error)
{
//do something
}
}
After SendTransaction is called, the Maiar app receives a notification to sign the transaction. If the user approvees the transaction, the signature will be automatically applied, and the transaction will be sent to MultiversX Blockchain for processing. In this case, an operationStatus of Complete will be received. If the user declines to sign or an error occurs, an operationStatus of Error will be received.
This concludes the send ESDT transaction Unity tutorial.
Recommended next: Send NFT Transaction