-
Notifications
You must be signed in to change notification settings - Fork 3
Send EGLD Transaction
This section shows you how to send an EGLD 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 send a transaction this API method will be used
/// <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 SendEGLDTransaction(string destinationAddress, string amount, string data, UnityAction<OperationStatus, string> TransactionStatus)
To be more clear here is a usage example:
private string defaultAddress = "erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf"; //address to send the transaction
private string defaultMessage = "You see this?"; //a message for the receiver
private double egld = 0.001; //amount of EGLD to send
//method connected to a button
public void SendTransaction()
{
MultiversXUnityTools.Manager.SendEGLDTransaction(defaultAddress, egld.ToString(), defaultMessage, 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 == MultiversXUnityTools.OperationStatus.Complete)
{
// store the transaction hash for later use
txHash = message;
//check the status of the transaction. More details in the next section
MultiversXUnityTools.Manager.CheckTransactionStatus(txHash, BlockchainTransactionListener, 6);
}
if (operationStatus == MultiversXUnityTools.OperationStatus.Error)
{
//do something
}
}
After SendTransaction is called, the Maiar app will receive a notification to sign the transaction. If the user decides to approve the transaction, the signature will be automatically applied, and the transaction will be sent automatically 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 EGLD transaction Unity tutorial.
Recommended next: Check Transaction Status