Unity - Can't authenticate with wallets

Hi there, thanks for the amazing work!
I am having an issue when I try to authenticate with the QR code in Unity:
When I use Trust Wallet or Iam Token to capture the QR, it sends the request correctly, then receive back the confirmation message inside the wallet.
However when accepting the request, the loggin fails, and this shows in Unity’s consol, related to UserServiceExtensions.cs :

NullReferenceException: Object reference not set to an instance of an object
Moralis.Platform.Services.ClientServices.UserServiceExtensions+<>c__DisplayClass18_01[TUser].<LogInWithAsync>b__0 (System.Threading.Tasks.Task1[TResult] task) (at Assets/MoralisWeb3ApiSdk/Moralis/MoralisDotNet/Platform/Services/ClientServices/UserServiceExtensions.cs:191)
Moralis.Platform.Utilities.InternalExtensions+<>c__DisplayClass5_02[TIn,TResult].<OnSuccess>b__0 (System.Threading.Tasks.Task t) (at Assets/MoralisWeb3ApiSdk/Moralis/MoralisDotNet/Platform/Utilities/InternalExtensions.cs:45) Moralis.Platform.Utilities.InternalExtensions+<>c__DisplayClass7_01[TResult].b__0 (System.Threading.Tasks.Task t) (at Assets/MoralisWeb3ApiSdk/Moralis/MoralisDotNet/Platform/Utilities/InternalExtensions.cs:72)
System.Threading.Tasks.ContinuationResultTaskFromTask1[TResult].InnerInvoke () (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Threading.Tasks.Task.Execute () (at <695d1cc93cca45069c528c15c9fdd749>:0) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0) Moralis.Platform.Utilities.InternalExtensions+<>c__DisplayClass7_01[TResult].b__0 (System.Threading.Tasks.Task t) (at Assets/MoralisWeb3ApiSdk/Moralis/MoralisDotNet/Platform/Utilities/InternalExtensions.cs:59)
System.Threading.Tasks.ContinuationResultTaskFromTask1[TResult].InnerInvoke () (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Threading.Tasks.Task.Execute () (at <695d1cc93cca45069c528c15c9fdd749>:0) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0) System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
MainMenuScript+d__11.MoveNext () (at Assets/MoralisWeb3ApiSdk/Example/Scripts/MainMenuScript.cs:199)
— End of stack trace from previous location where exception was thrown —
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:153)
UnityEngine.UnitySynchronizationContext:ExecuteTasks() (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:107)

What am I missing ?

thanks !

Hello, do you mean “accepting request” as in signing the authentication message ?
have you check if the version of the sdk is up to date ?
try to logout to clear the previous logged in cache and try again

Hi ! Thanks for your reply.
Yes, the error occurs when signing the authentication message.
Sending you the full log here to show where the issue is.
I have the latest version of the SDK and tried with unity 2020.3.23 and 2020.3.28

Hey, this should not stop other code from running and should not break anything, if this is stopping your other code from executing , you can provide more info about the code you are trying to execute.

And there is not yet a solution that I know off to fix this, but you can still build you project, this error should have no effect

it does stop other code! as wallet can’t connect ! and in the demo scene the address isnt shown on top of player.

hey, which version of the unity moralis sdk are you using ?
this should have been fixed with the recent release about some days ago ?

Hi ! thanks for your support, I am using v1.0.5.

The error disappeared ! yeha !

Nope, error is still there.

hey, this is a bit tricky error, but i get this error to, i dont think this is supposed to break the code

1 Like

I’m having this exact same error on the latest Moralis Tutorial:

1 Like

i have the same error here with binance testnet and mainnet

1 Like

hello dear
0xprof thank you for your help here i tested with the latest code but after singin and confirming in my wallet the error appear :

can you add this to the on application quit call back in unity
in your script that does connections stuffs

// Disconnect wallet subscription.
await walletConnect.Session.Disconnect();
// CLear out the session so it is re-establish on sign-in.
walletConnect.CLearSession();
// Logout the Moralis User.
await MoralisInterface.LogOutAsync();

I think the issue is that, session has not been cleared or logged out async

and before you do this the above, try and run the game again and press L, i think it should call a function that has this stuffs in it :thinking::thinking: , but if it doesnt, you can add it to the quit callback, so when you press stop when the app is playing, it should call this

1 Like

ohh yes thank you very much by pressing L it work again wow thank you sir

// Disconnect wallet subscription.
await walletConnect.Session.Disconnect();
// CLear out the session so it is re-establish on sign-in.
walletConnect.CLearSession();
// Logout the Moralis User.
await Moralis.LogOutAsync();

new sdk interface logout and clear cache