- Notifications
You must be signed in to change notification settings - Fork 3
All API Methods
All API methods are static and are available inside Manager.cs
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>publicstaticvoidConnect(UnityAction<AccountDto>OnWalletConnected,UnityActionOnWalletDisconnected,ImageqrImage)Usage example:
//method callMultiversXUnityTools.Manager.Connect(OnConnected,OnDisconnected,qrImage);privatevoidOnConnected(AccountconnectedAccount){//do actions with the connected wallet}privatevoidOnDisconnected(){//do actions when wallet disconected from the app}Simple check for connection status
/// <returns>true - if connection to the wallet is active</returns>publicstaticboolIsWalletConnected()Usage example:
//method callif(MultiversXUnityTools.Manager.IsWalletConnected()==true){//do something if connection is active}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.
publicstaticvoidDeepLinkLogin()Usage example:
MultiversXUnityTools.Manager.DeepLinkLogin();Send an EGLD transaction for signing to the Maiar wallet. After the signing, the transaction is 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>publicstaticvoidSendEGLDTransaction(stringdestinationAddress,stringamount,stringdata,UnityAction<OperationStatus,string>TransactionStatus)Usage example:
//Method callMultiversXUnityTools.Manager.SendEGLDTransaction("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>privatevoidSigningStatusListener(MultiversXUnityTools.OperationStatusoperationStatus,stringmessage){if(operationStatus==MultiversXUnityTools.OperationStatus.Complete){//save transaction hash//txHash = message;//check transaction status}}Send an ESDT transaction for signing to the Maiar wallet. After the signing the transaction is 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>publicstaticvoidSendESDTTransaction(stringdestinationAddress,Tokentoken,stringamount,UnityAction<OperationStatus,string>TransactionStatus)Usage example:
//Method callMultiversXUnityTools.Manager.SendESDTTransaction("erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf",MultiversXUnityTools.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>privatevoidSigningStatusListener(MultiversXUnityTools.OperationStatusoperationStatus,stringmessage){if(operationStatus==MultiversXUnityTools.OperationStatus.Complete){//save transaction hash//txHash = message;//check transaction status}}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>publicstaticvoidLoadWalletNFTs(UnityAction<OperationStatus,string,NFTMetadata[]>LoadNFTsComplete)Usage example:
//Method callMultiversXUnityTools.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>privatevoidLoadNFTComplete(MultiversXUnityTools.OperationStatusoperationStatus,stringmessage,MultiversXUnityTools.NFTMetadata[]allNfts){if(operationStatus==MultiversXUnityTools.OperationStatus.Complete){//after all metadata is loaded display the NFTsfor(inti=0;i<allNfts.Length;i++){DisplayNft(allNfts[i]);}}else{Debug.Log(operationStatus+" "+message);}}Send an NFT to the destination address. After the signing, the transaction is 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>publicstaticvoidSendNFT(stringdestinationAddress,stringcollectionIdentifier,ulongnftNonce,intquantity,UnityAction<OperationStatus,string>TransactionStatus)Usage example:
//Method callMultiversXUnityTools.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>privatevoidCompleteListener(MultiversXUnityTools.OperationStatusoperationStatus,stringmessage){if(operationStatus==MultiversXUnityTools.OperationStatus.Complete){//save transaction hash//txHash = message;//check transaction status}}To get any information about SC, a query needs to be performed.
/// <summary>/// Make a smart contract query/// </summary>/// <typeparam name="T">Query response type</typeparam>/// <param name="scAddress">The address of the smart contract</param>/// <param name="methodName">The method to call</param>/// <param name="QueryComplete">Callback to get the result of the query after finished</param>/// <param name="outputType">Type of expected result</param>/// <param name="args">The list of arguments</param> publicstaticvoidMakeSCQuery<T>(stringscAddress,stringmethodName,UnityAction<OperationStatus,string,T>QueryComplete,TypeValueoutputType,paramsIBinaryType[]args)whereT:IBinaryTypeUsage example:
//Method call. This will call the getSum method from the above SC//If the method you are calling has no parameters, send null as a param MultiversXUnityTools.Manager.MakeSCQuery<NumericValue>("erd1qqqqqqqqqqqqqpgqmm2m825y2t9nya0yqeg3nqlh2q50e7pd0eqq98uw2e","getSum",QueryComplete,TypeValue.BigUintTypeValue);/// <summary>/// Triggered when Smart contract query is complete/// </summary>/// <param name="operationStatus">Completed, In progress or Error</param>/// <param name="message">additional message</param>/// <param name="data">deserialized returned data</param>privatevoidQueryComplete(OperationStatusoperationStatus,stringmessage,NumericValuedata){if(operationStatus==OperationStatus.Complete){scResultText.text="Current sum: "+data;}else{scResultText.text=message;}}A Smart Contract method call will execute a code inside the Smart Contract. The data payload of the transaction delivers these calls to the blockchain so it needs to be signed by the user.
/// <summary>/// Call a smart contract method/// </summary>/// <param name="scAddress">The address of the smart contract</param>/// <param name="methodName">The method to call</param>/// <param name="gas">The gas required to execute the called SC method</param>/// <param name="CallStatus">Callback to get the result of the call</param>/// <param name="args">The list of arguments. Can be:</param>/// Address/// BooleanValue/// BytesValue/// EnumValue/// MultiValue/// NumericValue/// OptionValue/// StructValue/// TokenIdentifierValuepublicstaticvoidCallSCMethod(stringscAddress,stringmethodName,longgas,UnityAction<OperationStatus,string>CallStatus,paramsIBinaryType[]args)Usage example:
//Method callMultiversXUnityTools.Manager.CallSCMethod("erd1qqqqqqqqqqqqqpgqmm2m825y2t9nya0yqeg3nqlh2q50e7pd0eqq98uw2e","add",1500000,CallStatus,NumericValue.BigIntValue(10));/// <summary>/// Listener for the call response/// </summary>/// <param name="operationStatus">Completed, In progress or Error</param>/// <param name="message">additional message</param>privatevoidCallStatus(OperationStatusoperationStatus,stringmessage){if(operationStatus==OperationStatus.Complete){txHash=message;scResultText.text=$"Pending TX: {txHash}";Manager.CheckTransactionStatus(txHash,SCTransactionListener,1);}if(operationStatus==OperationStatus.Error){//do somethingscResultText.text=operationStatus+" "+message;}}Check the status of a specific transaction (whether 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>publicstaticvoidCheckTransactionStatus(stringtxHash,UnityAction<OperationStatus,string>TransactionStatus,floatdelay)Usage example:
//Method callMultiversXUnityTools.Manager.CheckTransactionStatus(txHash,TransactionProcessed,1);/// <summary>/// Listener for the transaction status response/// </summary>/// <param name="operationStatus">Completed, In progress or Error</param>/// <param name="message">additional message</param>privatevoidTransactionProcessed(OperationStatusoperationStatus,stringmessage){if(operationStatus==OperationStatus.Complete){//after a transaction is processed, refresh account balanceManager.RefreshAccount(RefreshDone);}else{//do something if failed}}Get the corresponding url based on selected API
/// <summary>/// Returns the URL associated with Endpoint/// </summary>/// <param name="endpoint">endpoint defined inside settings window</param>/// <returns></returns>publicstaticstringGetEndpointUrl(EndpointNamesendpoint)Usage example:
For an endpoint defined in settings window like this:
This is the call:
stringurl=Manager.GetEndpointUrl(EndpointNames.GetAccounts).Replace("{address}","erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf");url will be: https://devnet-api.elrond.com/accounts/erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf
/// <summary>/// Generic API Get request/// </summary>/// <typeparam name="T">Return type</typeparam>/// <param name="url">Get API url</param>/// <param name="CompleteMethod">Complete listener (operation status, error message, return data</param>publicstaticvoidGetRequest<T>(stringurl,UnityAction<OperationStatus,string,T>CompleteMethod)Here is a simple example used to get the info about an erd address.
//construct the url for the Get requeststringurl="https://devnet-api.elrond.com/accounts/erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf";//make the Get requestManager.GetRequest<AccountDto>(url,CompleteMethodGet);//receive the result inside Complete MethodprivatevoidCompleteMethodGet(OperationStatusoperationStatus,stringmessage,AccountDtoresult){if(operationStatus==OperationStatus.Complete){Debug.Log(result.Address);}else{Debug.LogError(message+" "+result);}}Post requests are used to send information to the blockchain and receive a response.
/// <summary>/// Make a POST request to MultiversX APIs/// </summary>/// <param name="url">Post url</param>/// <param name="jsonData">json data to send</param>/// <param name="CompleteMethod">Complete listener (operation status, error message, return data)</param>publicstaticvoidPostRequest<T>(stringurl,stringjsonData,UnityAction<OperationStatus,string,T>CompleteMethod)Here is a simple example on how to get the gas cost for a transaction before submitting it to the blockchain:
//construct the urlstringurl="https://devnet-gateway.elrond.com/transaction/cost";//construct the params as a json stringstringjson="{"+"\"nonce\":0,"+"\"sender\":\"erd1lgp3ezf2wfkejnu0sm5y9g4x3ad05gr8lfc0g69vvdwwj0wjv0gscv2w4s\","+"\"receiver\":\"erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf\","+"\"value\":\"1000000000000000\","+"\"gasPrice\":1000000000,"+"\"gasLimit\":89000,"+"\"data\":\"WW91IHNlZSB0aGlzPw==\","+"\"chainId\":\"D\","+"\"version\":1,"+"\"signature\":\"72ddcb105778051ea2a6f92b3869e2110d50f708708a2a3fe842014c062152c8aff78dae39868d97d25831915d3c60f4acfc749dfa8bdfa395f3769d2e231a05\""+"}";//Make the Post request MultiversXUnityTools.Manager.PostRequest(url,json,CompleteMethod);//receive the result inside Complete MethodprivatevoidCompleteMethod(OperationStatusoperationStatus,stringmessage,TransactionCostDataDtoresult){if(operationStatus==OperationStatus.Complete){Debug.Log(result.TxGasUnits);}else{Debug.LogError(message+" "+result.ReturnMessage);}}Close the connection with the wallet
publicstaticvoidDisconnect()Usage example:
MultiversXUnityTools.Manager.Disconnect();