WalletConnect / WalletConnectUnity

[DEPRECATED] WalletConnect v2 and Modal for Unity 🎮
MIT License
151 stars 49 forks source link

eth_getbalance request never ends #96

Closed laureveler closed 10 months ago

laureveler commented 1 year ago

I had this working on v2 prior to the recent updates. Pseudo-code:

 [RpcMethod("eth_getBalance"), RpcRequestOptions(Clock.ONE_MINUTE, 99998)]
    public class EthGetBalance : List<string>
    {
        public EthGetBalance(string address, BigInteger? blockNumber = null) : base(new[] { address, blockNumber != null ? blockNumber.ToString() : "latest" }) { }
    }

async void GetBalanceRoutine 
{
      _request = new EthGetBalance(wallet.WalletAddress);
      BigInteger result = await WCSignClient.Instance.Request<EthGetBalance, BigInteger>(_wallet.Session.Topic, _request, _wallet.ChainId);     
      Debug.Log(result);
}

Now the await statement never ends. Anyone had any luck with this?

gigajuwels commented 1 year ago

WalletConnect protocol does technically support this RPC however, this requires the dApp and wallet to agree on allowing this method(s) via required and optional namespaces. And according to @pedrouid

no wallet that (I know of) accepts [them] (eth_getBalance)

laureveler commented 1 year ago

Interesting - I do have this working in editor on a version of the demo app from a few months ago ? This was WCV2, when the demo app would only work in editor (so this is only editor tested). I was connecting with a Metamask wallet on the Mumbai Testnet. I did run into problems when attempting the request more than once, but the 1st request yields a result (and still does - I've just re-tested).

[RpcMethod("eth_getBalance"), RpcRequestOptions(Clock.ONE_MINUTE, 99998)]
public class EthGetBalance : List<string>
{
    public EthGetBalance(string address, BigInteger? blockNumber = null) : base(new[] { address, blockNumber != null ? blockNumber.ToString() : "latest" }) { }    
}

 public IEnumerator GetBalanceRoutine(Action<float> onComplete)
    {        
        Debug.Log("Getting balance routine started");
        _task = WCSignClient.Instance.Request<EthGetBalance, string>(_wallet.Session.Topic, _request, _wallet.ChainId);
        _wait = new WaitForTaskResult<string>(_task);
        yield return _wait;

        Debug.Log(_task.Result);
        _longResult = Convert.ToInt64(_task.Result, 16);
        Debug.Log(_longResult);
        _latestBalance = _longResult / _divisor;

        onComplete?.Invoke(_latestBalance);
        Debug.Log("Got balance: " + _latestBalance);
    }

Gives me the following result:

Getting balance routine started
UnityEngine.Debug:Log (object)
WalletBalance/<GetBalanceRoutine>d__12:MoveNext () (at Assets/Scripts/WalletBalance.cs:53)

0xc7c15bea0ea74a8
UnityEngine.Debug:Log (object)
WalletBalance/<GetBalanceRoutine>d__12:MoveNext () (at Assets/Scripts/WalletBalance.cs:59)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

899617934054945960
UnityEngine.Debug:Log (object)
WalletBalance/<GetBalanceRoutine>d__12:MoveNext () (at Assets/Scripts/WalletBalance.cs:61)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

Got balance: 0.899618
UnityEngine.Debug:Log (object)
WalletBalance/<GetBalanceRoutine>d__12:MoveNext () (at Assets/Scripts/WalletBalance.cs:65)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

I'm going to double check using this exact code in the newer version in the coming days/week, hopefully (in writing this post I've dug out the old project where I had it working).

laureveler commented 1 year ago

Yes, so using the same code as above in the newest version, I get the following error:

WalletConnectException: Missing or invalid parameter
WalletConnectSharp.Sign.Engine.WalletConnectSharp.Sign.Interfaces.IEnginePrivate.IsValidRequest[T] (System.String topic, WalletConnectSharp.Network.Models.JsonRpcRequest`1[T] request, System.String chainId) (at <3727d9dac3144b508fbc52930398e78a>:0)
WalletConnectSharp.Sign.Engine.Request[T,TR] (System.String topic, T data, System.String chainId, System.Nullable`1[T] expiry) (at <3727d9dac3144b508fbc52930398e78a>:0)
Rethrow as AggregateException: One or more errors occurred. (Missing or invalid parameter)
adam-bloktopia commented 10 months ago

Any updates on when a fix for this bug might be coming?

skibitsky commented 10 months ago

Most wallets still don't support eth_getBalance. We recommend sending this request directly to RPC node. Added explanation and code sample to the WalletConnect Modal docs.

tl;dr