Hello, I was trying to test and learn this tutorial.
When I try to send transaction, I get this error.
Here is the OtherPlayerPanel. It is very similar to the script in this tutorial.
How can I find the reason why the transaction process did not happen? Where do you think I might be going wrong? It’s a PC project btw. I use moralisweb3sdk_v1_2_1 package and PUN2. Thanks for support or any help.
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
//MORALIS
using MoralisUnity;
using MoralisUnity.Platform.Objects;
using MoralisUnity.Web3Api.Models;
using Nethereum.Util;
#if UNITY_WEBGL
using System.Numerics;
using Moralis.WebGL.Hex.HexTypes;
using Moralis.WebGL.Models;
#else
using Nethereum.Hex.HexTypes;
using Nethereum.RPC.Eth.DTOs;
#endif
public class OtherPlayerPanel : MonoBehaviour
{
[Header("Info Panel")]
public GameObject infoPanel;
public TextMeshProUGUI toUsernameLabel;
public TextMeshProUGUI toAddressLabel;
[Header("Transaction Panel")]
public GameObject transactionPanel;
public Button executeButton;
public TMP_InputField inputField;
private string _toAddress;
private string _toUsername;
private void OnEnable()
{
infoPanel.SetActive(true);
transactionPanel.SetActive(false);
}
private void OnDisable()
{
inputField.text = String.Empty;
}
public void SetInformation(string clickedUsername, string clickedWalletAddress)
{
_toUsername = clickedUsername;
_toAddress = clickedWalletAddress;
toUsernameLabel.text = "Username:<br>" + clickedUsername;
toAddressLabel.text = "Wallet Address:<br>" + clickedWalletAddress;
Debug.Log("Information set!!!!");
}
public void HandleTransferButtonClick()
{
/*
#if UNITY_WEBGL
ExecuteTransferWebGL();
#else
ExecuteTransfer();
#endif
*/
ExecuteTransfer();
}
public void HandleOnValueChanged()
{
if (inputField.text == String.Empty)
{
executeButton.interactable = false;
}
else
{
executeButton.interactable = true;
}
}
#if UNITY_WEBGL
private async void ExecuteTransferWebGL()
{
var nativeAmount = float.Parse(inputField.text);
var weiAmount = UnitConversion.Convert.ToWei(nativeAmount);
// Retrieve from address, the address used to authenticate the user.
var user = await MoralisInterface.GetUserAsync();
string fromAddress = user.authData["moralisEth"]["id"].ToString();
// Create transaction request.
TransactionInput txnRequest = new TransactionInput()
{
Data = String.Empty,
From = fromAddress,
To = _toAddress,
Value = new HexBigInteger(weiAmount)
};
try
{
// Execute the transaction.
string txnHash = await MoralisInterface.SendTransactionAsync(txnRequest.To, txnRequest.Value);
Debug.Log($"Transfered {weiAmount} WEI from {fromAddress} to {toAddressLabel}. TxnHash: {txnHash}");
}
catch (Exception exp)
{
Debug.Log($"Transfer of {weiAmount} WEI from {fromAddress} to {toAddressLabel} failed!");
}
}
#else
private async void ExecuteTransfer()
{
var nativeAmount = float.Parse(inputField.text);
var weiAmount = UnitConversion.Convert.ToWei(nativeAmount); // convert to WEI
// Retrieve from address, the address used to authenticate the user.
MoralisUser user = await Moralis.GetUserAsync();
string fromAddress = user.authData["moralisEth"]["id"].ToString();
// Create transaction request.
TransactionInput txnRequest = new TransactionInput()
{
Data = String.Empty,
From = fromAddress,
To = _toAddress,
Value = new HexBigInteger(weiAmount)
};
try
{
// Execute the transaction.
//string txnHash = await MoralisInterface.Web3Client.Eth.TransactionManager.SendTransactionAsync(txnRequest);
string txnHash = await Moralis.Web3Client.Eth.TransactionManager.SendTransactionAsync(txnRequest);
Debug.Log($"Transfered {weiAmount} WEI from {fromAddress} to {_toAddress}. TxnHash: {txnHash}");
}
catch (Exception exp)
{
Debug.Log($"Transfer of {weiAmount} WEI from {fromAddress} to {_toAddress} failed!");
}
}
#endif
}