public static void CallSCMethod(string scAddress, string methodName, long gas, UnityAction<CompleteCallback<string[]>> completeMethod, params IBinaryType[] args)
Parameters
Name
Description
scAddress
The address of the smart contract.
methodName
The method to call.
gas
The gas required to execute the called SC method.
completeMethod
Callback to get the result of the call.
args
The list of arguments. Can be of type: BooleanValue, BytesValue, EnumValue, MultiValue, NumericValue, OptionValue, StructValue, TokenIdentifierValue
Example
This method increases with 10 the value from the basic adder smart contract.
public class Test : MonoBehaviour
{
public void Call()
{
MultiversX.UnityTools.API.CallSCMethod("erd1qqqqqqqqqqqqqpgqmm2m825y2t9nya0yqeg3nqlh2q50e7pd0eqq98uw2e", "add", 1500000, CompleteMethod, NumericValue.BigUintValue(10));
}
private void CompleteMethod(CompleteCallback<string[]> result)
{
switch (result.status)
{
case OperationStatus.InProgress:
Debug.Log($"Waiting for xPortal signature");
break;
case OperationStatus.Error:
Debug.LogError($"{result.errorMessage}");
break;
case OperationStatus.Success:
//result.data contains the hash of the transaction
//at this point transaction is broadcasted to the blockchain to be processed
//use this method to check if it was processed succesfully or not
MultiversX.UnityTools.API.CheckTransactionStatus(result.data, TransactionProcessed, 1);
break;
}
}
private void TransactionProcessed(CompleteCallback<Transaction[]> result)
{
switch (result.status)
{
case OperationStatus.InProgress:
foreach (Transaction transaction in result.data)
{
Debug.Log($"Tx: {transaction.TxHash} : {transaction.Status}");
}
break;
case OperationStatus.Success:
Debug.Log("Success");
break;
case OperationStatus.Error:
Debug.LogError($"{result.status} {result.errorMessage}");
foreach (Transaction transaction in result.data)
{
//the GetLogs() will return additional info about why the transaction failed.
Debug.Log($"Tx: {transaction.TxHash} : {transaction.Status} {transaction.GetLogs()}");
}
break;
}
}
}