Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection error and transaction failed #190

Open
Dejavu0709 opened this issue Mar 28, 2024 · 6 comments
Open

Connection error and transaction failed #190

Dejavu0709 opened this issue Mar 28, 2024 · 6 comments
Labels

Comments

@Dejavu0709
Copy link

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));
    }
@skibitsky
Copy link
Member

Thanks for opening the issue.

  1. Is the provided code called from the main thread?
  2. Are you using a VPN? Have you tried turning it off?
  3. Does this issue occur after the game has been active for some time, or is it closer to the game's launch?

@Dejavu0709
Copy link
Author

1.Yes,I called it by a button click on mono
2.Yes, Because I am in China, I can not try it without vpn, is there some way I can try it without vpn?
3.Both may occur, for example, a game launch only for a while, I called a transaction and wake the metamask, if I choose neither accept nor reject the transaction, when I back to the game, the issue will very likely occur.

here is a log today for this issue:

[WebSocketConnection-daced119-da82-4851-b815-f203d47a8847] Got payload:
{"id":438221287113216,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"f21bf0eb3d4dee99ad71ff00db636a74b0e54f3c8d84af517342f44d8edfc61f","data":{"topic":"d53c3d64ad37cd5595556323766e73b8660529dbc7084b8bf2de4b4942801a54","message":"AICDV8ZPmtwSb1CkJNQGIV8e/YEEKjvcQ0dcNWaU4Qa7ksvu30ADGa0QpGqbjBXkDHuiP285a87pU1XofaCxKG/6E7HQum6RuxU7rHi9U/fxfSHhlh3K7x7ig++co+R3ria7Nhc9Bah7CVcPSgDGVAEdNreSuF7ZCylLX9BuPLvaIXgJU0OwGJ4OAakAO/zCE9LCgKTKlBaAWF4lmB658aMlfiNAN9ZAG92PYV8nKQkuIv2HB5PJMxCX7UG9/orZl9INGJ2ZMV9Va1M5UMgMayVnDkRuCXJeYdYAfilKrCTE98v2zTSMfGtawpo4fnhVyh4ag9FdJkzReweh67N4OPQXFR9q3OTA1xFMW8iHnGn6uW8FbIQlOe4NvH/aFdEkNAGK9msZASyi3y7ohs3/ovTt/1SWGu8wRf0qAonOF5UvfNIAkZ8qYld8uBFLJvBlpJEvUEyxHy2+roE7XWdm2H5dobJIpZxMT8qPUp7xTaKxxSAU3Z4yfNWNRs5zL0F1owQG05DVRBUfYn/fA82V1A1iC2s6fO5HT//RFZC/vbkbIe0x/bSAhHkucQvaJMhO+MKGXyk=","publishedAt":1711801902627,"tag":1104}}}
[JsonRpcProvider] Got payload {"id":438221287113216,"jsonrpc":"2.0","error":{"code":-2146233088,"message":"One or more errors occurred. (The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseReceived')","data":null},"result":false}

@skibitsky
Copy link
Member

2.Yes, Because I am in China, I can not try it without vpn, is there some way I can try it without vpn?

I see that you are using wss://relay.walletconnect.org, which should work without a VPN in China. Could you please try turning off the VPN?

@Dejavu0709
Copy link
Author

signClient.Options.RelayUrl = "wss://relay.walletconnect.org";

Hi,thanks for the reply。
Without vpn, connect wallet page can not get the wallets info,I use vpn to pass this step,and close the vpn,then I send a transaction, but I even can not invoke the metamask app, it will keep in the game app cannot jump to the metamask

@skibitsky
Copy link
Member

Can you access web3modal.com from your browser without VPN?

@Dejavu0709
Copy link
Author

Can you access web3modal.com from your browser without VPN?

Yes,I can do this without vpn, 5G and wifi both work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants