-
Notifications
You must be signed in to change notification settings - Fork 46
Description
Describe the bug
We try to send smart contract transaction,and we meet some issues,it works not stable,sometimes it works and sometimes didnot
the first issue is :
#186
the second one is: Error Unity WebSocketException: The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseReceived'
and here is the log:
2024/03/25 11:46:50.455 19933 20000 Error Unity WebSocketException: The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseReceived'
2024/03/25 11:46:50.455 19933 20000 Error Unity at System.Net.WebSockets.WebSocketValidate.ThrowIfInvalidState (System.Net.WebSockets.WebSocketState currentState, System.Boolean isDisposed, System.Net.WebSockets.WebSocketState[] validStates) [0x00000] in <00000000000000000000000000000000>:0
2024/03/25 11:46:50.455 19933 20000 Error Unity at System.Net.WebSockets.ManagedWebSocket.SendPrivateAsync (System.ReadOnlyMemory1[T] buffer, System.Net.WebSockets.WebSocketMessageType messageType, System.Boolean endOfMessage, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0 2024/03/25 11:46:50.455 19933 20000 Error Unity at System.Net.WebSockets.ManagedWebSocket.SendAsync (System.ArraySegment1[T] buffer, System.Net.WebSockets.WebSocketMessageType messageType, System.Boolean endOfMessage, System.Threading.CancellationToken cancellationToken) [0x00000] in <00000000000000000000000000000000>:0
2024/03/25 11:46:50.455 19933 20000 Error Unity at NativeWebSocket.WebSocket.SendMessage (System.Collections.Generic.List`1[T] q
To Reproduce
connect the wallet with metamask
and send a transaction to smart contract
Expected behavior
succsse to send a transaction
Environment
- OS: [android ]
- Unity version [e.g. 2021.3.5f1]
- Package name and version [e.g. WalletConnectUnity Modal v1.1.0]
Is this happening in Unity Editor or on a player like Android, iOS, Windows?
Both on Editor and Android
Wallets used for testing
Metamask
Additional context
My code is here:
Nethereum.ABI.Model.Parameter[] parameters = new Nethereum.ABI.Model.Parameter[] {
new("uint16", "_prizeTypeIdx"),
new("uint256", "_prizeOpenId"),
new("uint16", "_prizeMultiplier"),
new("uint256", "_prizePayFee"),
new("address", "_prizeNftAddress"),
new("uint256", "_prizeNftTokenId"),
new("uint256", "_prizeNftAmount"),
new("address", "_prizeDamAddress"),
new("uint256", "_prizeDamAmount"),
new("address", "_prizeDioAddress"),
new("uint256", "_prizeDioAmount"),
// new("uint256", "_deadline"),
new("bytes", "_sig"),
};
var functionCallEncoder = new FunctionCallEncoder();
var sha3Signature = new Sha3Keccack().CalculateHash("claimWithoutSig(uint16,uint256,uint16,uint256,address,uint256,uint256,address,uint256,address,uint256,bytes)");
// Encode the parameters
var encodedParameters = functionCallEncoder
.EncodeParameters(parameters, (int)type, (BigInteger)reward.open_id, (BigInteger)reward.Multipier, (BigInteger)reward.PayFree,
_prizeNftAddress, _prizeNftTokenId, _prizeNftAmount,
_prizeDamAddress, _prizeDamAmount,
_prizeDioAddress, _prizeDioAmount,
Encoding.UTF8.GetBytes(reward.sign))
//(BigInteger)reward.deadline, Encoding.UTF8.GetBytes(reward.sign))
// .EncodeParameters(parameters, "xxxx", "yyyy")
.ToHex();
// Combine signature and parameters
var data = "0x" + sha3Signature[..8] + encodedParameters;
var web3 = new Nethereum.Web3.Web3(RPC);
//Debug.Log("web3.Eth.GasPrice" + web3.Eth.GasPrice);
Debug.Log("transaction data:" + data);
Debug.Log("transaction function data:" + sha3Signature[..8]);
// Create transaction
var ethSendTransaction = new EthSendTransaction(new Transaction
{
From = myAddress,
To = ContractAddress,
Value = "0",
Data = data,
//Gas = "2100000",
// GasPrice = "2500000000",
});
try
{
var signClient = WalletConnect.Instance.SignClient;
signClient.Options.RelayUrl = "wss://relay.walletconnect.org";
Debug.Log(" signClient.Options.RelayUrl:" + signClient.Options.RelayUrl);
//var result = await signClient.Request<EthSendTransaction, string>(ethSendTransaction);
//WalletConnect.Instance.RequestAsync<EthSendTransaction, string>(ethSendTransaction);
var result = await WalletConnect.Instance.RequestAsync<EthSendTransaction, string>(ethSendTransaction);
Debug.LogError($"Transaction success! TxHash: {result}", this);
if (result.Contains("0x"))
callBackFunction?.Invoke(new RequestResult(true, reward));
else
callBackFunction?.Invoke(new RequestResult(false, reward));
Debug.Log($"Transaction success! callBackFunction: ", this);
}
catch (Exception e)
{
Debug.LogError(e.Message + e.StackTrace, this);
callBackFunction?.Invoke(new RequestResult(false, reward));
}