Ethereum Unity3D Boilerplate Questions

PLEASE HELP! I canā€™t run it on my local PC at home, as itā€™s a COMPLETELY different setup from the Server I run my site on. Iā€™ve only EVER run it on my server, NEVER on my home PC.
So, assume my server IS local, because Iā€™m running terminal commands on it, installing everything on it. It IS my local machine.

I actually canā€™t test as per the ā€œnormalā€ instructions you give, as Iā€™m on an older version (Iā€™ve been developing from the start), Iā€™m using MoralisWeb3ApiSdk and donā€™t know exactly how to transfer everything (unless thereā€™s a legacy tutorial Iā€™m missing).

So, server side, hereā€™s what Iā€™m getting in dev browser:

Setup default wallet MetaMask
build.framework.js:3454:11
Closing Websocket
build.framework.js:3454:11
[WebSocket] Queued 0 subscriptions
build.framework.js:3454:11
[WebSocket] Flushing Queue
build.framework.js:3454:11
[WebSocket] Queue Count: 0
build.framework.js:3454:11
[WebSocket] Queue Flushed
build.framework.js:3454:11
[WebSocket] Opened wss://k.bridge.walletconnect.org
build.framework.js:3454:11
[WebSocket] Open Completed
build.framework.js:3454:11
[WebSocket] Subscribe to 00711fc7-6943-495a-9e95-59b952a2dd93
[WalletConnect] Session Connected
build.framework.js:3454:11
Wallet connection received
build.framework.js:3454:11
Adding Header: Content-Type value: application/json
build.framework.js:3454:11
Adding Header: X-Parse-Installation-Id value: 89268d3a-00c0-4c9f-a690-5d84e89ded7f
build.framework.js:3454:11
Adding Header: X-Parse-Application-Id value: pRLSWTZ8RUMngGVmgWmI8IzaUXFgUsX8Z1wZ6leJ

Everything looks nice until this comes next:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:1337/server/functions/getServerTime. (Reason: CORS request did not succeed). Status code: (null).

Error: Unknown Error
build.framework.js:3447:11
    _JS_Log_Dump https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:3447
    __Z19WebGLPrintfConsolev7LogTypePKcPi https://devilsandangels.io/DnA/selfhost/Build/build.wasm:3566522
    __ZL20InternalErrorConsolePKcz https://devilsandangels.io/DnA/selfhost/Build/build.wasm:3566134
    __Z40DebugStringToFilePostprocessedStacktraceRK21DebugStringToFileData https://devilsandangels.io/DnA/selfhost/Build/build.wasm:3565055
    __Z17DebugStringToFileRK21DebugStringToFileData https://devilsandangels.io/DnA/selfhost/Build/build.wasm:3558400
    __Z35DebugLogHandler_CUSTOM_Internal_Log7LogType9LogOptionP12Il2CppStringP12Il2CppObject https://devilsandangels.io/DnA/selfhost/Build/build.wasm:8283213
    _DebugLogHandler_Internal_Log_mA1D09B6E813ABFAB6358863B6C2D28E3ACA9E101 https://devilsandangels.io/DnA/selfhost/Build/build.wasm:31767430
    _DebugLogHandler_LogFormat_mB876FBE8959FC3D9E9950527A82936F779F7A00C https://devilsandangels.io/DnA/selfhost/Build/build.wasm:31767509
    __ZN23InterfaceActionInvoker4IP12Il2CppObjectS1_S1_S1_E6InvokeEtP11Il2CppClassS1_S1_S1_S1_S1_ https://devilsandangels.io/DnA/selfhost/Build/build.wasm:18771301
    _Logger_Log_mBAF75BD87C8B66198F52DEFF72132C42CA369881 https://devilsandangels.io/DnA/selfhost/Build/build.wasm:31783982
    __ZN23InterfaceActionInvoker2IiP52Expression_t30A004209C10C2D9A9785B2F74EEED431A4D4660E6InvokeEtP11Il2CppClassP12Il2CppObjectiS1_ https://devilsandangels.io/DnA/selfhost/Build/build.wasm:14695275
    _Debug_LogError_m8850D65592770A364D494025FF3A73E8D4D70485 https://devilsandangels.io/DnA/selfhost/Build/build.wasm:31763403
    dynCall_vii https://devilsandangels.io/DnA/selfhost/Build/build.wasm:44484835
    dynCall_vii https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:29649
    invoke_vii https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:19712
    _U3CExecuteAsyncU3Ed__7_MoveNext_m744143852593D697E1D53BF7A60E79CCC1DF8834 https://devilsandangels.io/DnA/selfhost/Build/build.wasm:20984476
    __ZN23InterfaceActionInvoker06InvokeEtP11Il2CppClassP12Il2CppObject https://devilsandangels.io/DnA/selfhost/Build/build.wasm:14447826
    _AsyncUniTask_2_Run_m009C0A732E50F84A1D89607154BAB6B2ED52C5AC_gshared https://devilsandangels.io/DnA/selfhost/Build/build.wasm:14942216
    _LiveQueryConnectedHandler_Invoke_mE61D8C8CC2C366ADC8C6268763F59B1F037CB0A2 https://devilsandangels.io/DnA/selfhost/Build/build.wasm:17227853
    _PooledDelegate_1_Run_mF261E7CD6B10D4200AC35511CBBA8B01214F568C_gshared https://devilsandangels.io/DnA/selfhost/Build/build.wasm:28134715
    _LiveQueryErrorHandler_Invoke_m19D11A592A74DD8479C9F5E13E3D7BC86B20EBCB https://devilsandangels.io/DnA/selfhost/Build/build.wasm:17228652
    __Z57Action_1_Invoke_m587509C88BB83721D7918D89DF07606BB752D744P50Action_1_tD9663D9715FAA4E62035CFCF1AD4D094EE7872DCP12Il2CppObjectPK10MethodInfo https://devilsandangels.io/DnA/selfhost/Build/build.wasm:14551318
    _AsyncOperation_InvokeCompletionEvent_m2BFBB3DD63950957EDE38AE0A8D2587B900CB8F5 https://devilsandangels.io/DnA/selfhost/Build/build.wasm:31735268
    __Z65RuntimeInvoker_TrueVoid_t700C6383A2A510C2CF4DD86DABD5CA9FF70ADAC5PFvvEPK10MethodInfoPvPS4_ https://devilsandangels.io/DnA/selfhost/Build/build.wasm:14116933
    dynCall_iiiii https://devilsandangels.io/DnA/selfhost/Build/build.wasm:44480649
    dynCall_iiiii https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:28929
    invoke_iiiii https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:18272
    __ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException https://devilsandangels.io/DnA/selfhost/Build/build.wasm:43885784
    _il2cpp_runtime_invoke https://devilsandangels.io/DnA/selfhost/Build/build.wasm:43730338
    __Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb https://devilsandangels.io/DnA/selfhost/Build/build.wasm:3656359
    __ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb https://devilsandangels.io/DnA/selfhost/Build/build.wasm:3655169
    __ZN14AsyncOperation15InvokeCoroutineEv https://devilsandangels.io/DnA/selfhost/Build/build.wasm:5792438
    __ZN29UnityWebRequestAsyncOperation15InvokeCoroutineEv https://devilsandangels.io/DnA/selfhost/Build/build.wasm:13424490
    __ZN20UnityWebRequestProtoI24UnityWebRequestTransport16AtomicRefCounter14RedirectHelper14ResponseHelper15DownloadHandler13UploadHandler18CertificateHandler12HeaderHelper14AsyncOperationE19Job_InvokeCoroutineEPS8_ https://devilsandangels.io/DnA/selfhost/Build/build.wasm:13419842
    __ZN18BackgroundJobQueue21ExecuteMainThreadJobsEv https://devilsandangels.io/DnA/selfhost/Build/build.wasm:6406534
    __ZZ23InitPlayerLoopCallbacksvEN43EarlyUpdateExecuteMainThreadJobsRegistrator7ForwardEv https://devilsandangels.io/DnA/selfhost/Build/build.wasm:6494772
    __Z17ExecutePlayerLoopP22NativePlayerLoopSystem https://devilsandangels.io/DnA/selfhost/Build/build.wasm:6246330
    __Z17ExecutePlayerLoopP22NativePlayerLoopSystem https://devilsandangels.io/DnA/selfhost/Build/build.wasm:6246351
    __Z10PlayerLoopv https://devilsandangels.io/DnA/selfhost/Build/build.wasm:6242355
    __ZL8MainLoopv https://devilsandangels.io/DnA/selfhost/Build/build.wasm:6233694
    dynCall_v https://devilsandangels.io/DnA/selfhost/Build/build.wasm:44483642
    dynCall_v https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:29424
    browserIterationFunc https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:9752
    runIter https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:9854
    Browser_mainLoop_runner https://devilsandangels.io/DnA/selfhost/Build/build.framework.js:9790
Error Getting Wallet Info: Unknown Error

So:
Why is CORS failing? The Wallet connection succeeds but then CORS problem and:

KeyNotFoundException: The given key was not present in the dictionary.```

What does THAT mean? What key? the Moralis secret key? App id? Cli key? some key not in the moralis web dashboard?  I'm stuck..

You mentioned this is an older project in the other post (you can just keep to this topic now), what version of the Moralis SDK are you using? It should show in the Unity package manager window. Itā€™s best to try and get it working locally first.

How did you set up the self-hosted server exactly? By default you just install that project, set up the environment variables, start it and then you should be able to go to http://localhost:1337/server in your browser.

There is a migration video and some other info on that page.

It doesnā€™t show version in package manager, Iā€™ll see if I can find it elsewhere. And anyways migration isnā€™t an issue, everything was working smoothly on the Moralis server. And yes, considering the webGL is on my server, and the parser is also, it does run ā€œlocallyā€.

I gave you the terminal commands that I used to install the server already, but here Iā€™ll say it again:

yarn add parse-server --ignore-engines
yarn dev:db-start
yarn start
cd /var/www/html/DnA/parse-server-migration
yarn build
yarn start
yarn dev:db-start
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
yarn add parse-dashboard --ignore-engines
yarn add moralis --ignore-engines

That is all I did, then change the name of the env file in the parse-server code to .env following the parse-server guide. So yes, I ran the commands to run locally, and itā€™s not working. Iā€™m assuming Iā€™m missing something to do with the older moralis sdk Iā€™m using. Honestly I canā€™t seem to find the version anywhere, can you tell me? I call ā€˜using MoralisWeb3ApiSdkā€™ instead of the newer calls for Unity you have. PLEASE just give me a hint! Who wrote the code? Maybe THEY can take a look for me?
Dave

Okay so this happens when I try to start the parse server:

root@davecote:/var/www/html/DnA/parse-server-migration# yarn dev
yarn run v1.22.19
$ ts-node src/index.ts
bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
warn: DeprecationWarning: The Parse Server option 'directAccess' default will change to 'true' in a future version. Additionally, the environment variable 'PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS' will be deprecated and renamed to 'PARSE_SERVER_DIRECT_ACCESS' in a future version; it is currently possible to use either one.
warn: DeprecationWarning: The Parse Server option 'enforcePrivateUsers' default will change to 'true' in a future version.
warn: DeprecationWarning: The Parse Server option 'allowClientClassCreation' default will change to 'false' in a future version.
info: Parse LiveQuery Server started running
Moralis Server is running on port 1337 and stream webhook url https://1c9e-167-71-97-138.ngrok.io/streams-webhook
MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at Timeout._onTimeout (/var/www/html/DnA/parse-server-migration/node_modules/mongodb/src/sdam/topology.ts:577:30)
    at listOnTimeout (node:internal/timers:564:17)
    at processTimers (node:internal/timers:507:7) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) { 'localhost:27017' => [ServerDescription] },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

And before that error I got the same except instead of ECONNREFUSED I got:]

MongoServerSelectionError: Invalid message size: 1347703880, max allowed: 67108864

What am I getting wrong here?

Seems to still be an issue with your MongoDB connection, check your instance and your connection string (in .env). If you keep having issues with it locally, you could just set up a hosted MongoDB (Cloud) instance for now.

Iā€™ve always struggled with mongodb, I hate it actually. Would you happen to know how to do it by cloud?
Dave :slight_smile:

You can follow this tutorial.

Okay server is running:

root@davecote:/var/www/html/DnA/parse-server-migration# yarn dev
yarn run v1.22.19
$ ts-node src/index.ts
bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
warn: DeprecationWarning: The Parse Server option 'directAccess' default will change to 'true' in a future version. Additionally, the environment variable 'PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS' will be deprecated and renamed to 'PARSE_SERVER_DIRECT_ACCESS' in a future version; it is currently possible to use either one.
warn: DeprecationWarning: The Parse Server option 'enforcePrivateUsers' default will change to 'true' in a future version.
warn: DeprecationWarning: The Parse Server option 'allowClientClassCreation' default will change to 'false' in a future version.
info: Parse LiveQuery Server started running
Moralis Server is running on port 1337 and stream webhook url https://3494-167-71-97-138.ngrok.io/streams-webhook

But, same browser errors:

[WebSocket] Queued 0 subscriptions
build.framework.js:3454:11
[WebSocket] Flushing Queue
build.framework.js:3454:11
[WebSocket] Queue Count: 0
build.framework.js:3454:11
[WebSocket] Queue Flushed
build.framework.js:3454:11
[WebSocket] Opened wss://2.bridge.walletconnect.org
build.framework.js:3454:11
[WebSocket] Open Completed
build.framework.js:3454:11
[WebSocket] Subscribe to e48c6638-3688-476c-974d-9d6c5f939001
build.framework.js:3454:11
[WalletConnect] Session Connected
3 build.framework.js:3454:11
Wallet connection received
build.framework.js:3454:11
Adding Header: Content-Type value: application/json
build.framework.js:3454:11
Adding Header: X-Parse-Installation-Id value: dec524d9-62f3-4388-ae7a-73b04cba5c16
build.framework.js:3454:11
Adding Header: X-Parse-Application-Id value: pRLSWTZ8RUMngGVmgWmI8IzaUXFgUsX8Z1wZ6leJ
build.framework.js:3454:11
Setup default wallet MetaMask
build.framework.js:3454:11
WebGL warning: clientWaitSync: ClientWaitSync must return TIMEOUT_EXPIRED until control has returned to the user agent's main loop. (only warns once) 7
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:1337/server/functions/getServerTime. (Reason: CORS request did not succeed). Status code: (null).
2
Error: Unknown Error
build.framework.js:3447:11
Error Getting Wallet Info: Unknown Error

So this machine is ubuntu 20.04, run via terminal ssh, the webGL build is at devilsandangels.io/DnA/selfhost/ and the parse server is at devilsandangels.io:1337/server
Please ask me questions to get me to look up whatever I need to be looking at. Where are any logs that could help?
Dave :slight_smile:

And if I run the webGL in the Unity editor (not on the servers machine, on my home PC) it gives Error: Cannot connect to destination host (expected obviously) but then throws this:

[WebSocket] Exception Unexpected character encountered while parsing value: M. Path '', line 0, position 0.
UnityEngine.Debug:Log (object)
WalletConnectSharp.Unity.Network.NativeWebSocketTransport/<OnMessageReceived>d__29:MoveNext () (at Assets/MoralisWeb3ApiSdk/WalletConnectSharp.Unity/Network/NativeWebSocketTransport.cs:199)
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start<WalletConnectSharp.Unity.Network.NativeWebSocketTransport/<OnMessageReceived>d__29> (WalletConnectSharp.Unity.Network.NativeWebSocketTransport/<OnMessageReceived>d__29&)
WalletConnectSharp.Unity.Network.NativeWebSocketTransport:OnMessageReceived (byte[])
NativeWebSocket.WebSocket:DispatchMessageQueue () (at Assets/MoralisWeb3ApiSdk/WalletConnectSharp.Unity/Network/Client/NativeWebSocket.cs:701)
WalletConnectSharp.Unity.Network.NativeWebSocketTransport:Update () (at Assets/MoralisWeb3ApiSdk/WalletConnectSharp.Unity/Network/NativeWebSocketTransport.cs:208)

Does this point to anything?
D

These links donā€™t work for me.

Iā€™m not familiar with this error - this error isnā€™t coming from your own code? When does this happen? What is the server / dapp URL youā€™re using in the Unity SDK for your project?

Sorry links are:
Webgl https://devilsandangels.io/DnA/selfhost
Server http://devilsandangels.io:1337/server

And I donā€™t know, could it be that my older sdk is causing the problem? It happens right after scanning QR and then accepting connection in metamask on the mobile app on my phone. The browser on computer says successful connection please sign message. Then crash.

It could be - Iā€™m not that familiar with the older SDK code. You could share a repo of the Unity project. If you double click the error in the Unity editor, it may open the file where itā€™s coming from.

Those links still show 404 errors for me.

Ah, typo, links fixed please try again

With your game, I get this error when authenticating:

http://localhost:1337/server/functions/getServerTime 403 (Forbidden)

Have you used the right application ID?

I used the app id that it was always using, generated by moralis dashboard. Speaking to that, maybe some keys I have wrong. Where do I find A) MORALIS_API_KEY? B) MASTER_KEY?

Okay this is horrible. Is ANYONE having luck migrating? My Unity WebGL build ran perfectly on the moralis-hosted server, so why should any difference in the sdk Iā€™m using have any difference?
I ran a server locally on my home PC like you recommended, I get 403 unauthorized no matter what I try. So I installed a bunch of yarn and npm on my home setup and likely those software remnants will cause problems in the future.
Iā€™ve been using different APIā€™s since Stripe payments first came out, so I can navigate this stuff, and code decently in C#, js, python, php, C++, C ā€¦ and yet this seems rediculously impossible.
Seriously nobody there at moralis, or on this forum, has migrated the original sdk in a unity build to the web?? Just on ā€œlocalā€ machines?? How on earth are we supposed to work with this??
ANNNNNND: WHATā€™S MY MORALIS_API_KEY??? AND WHATā€™S MY MASTER_KEY???

You need to use the application ID you define in your serverā€™s environment variables (locally this is the .env file). This is where the master key is also set. You need to look at the self-hosted tutorial - you have missed a few other things.

Other users have already done this using the modifications I linked.

Self-hosted servers are slightly different - for example, they handle authentication differently meaning this code has to be changed in the clientside (like the Unity SDK). This is also covered in this tutorial - you need to be following this.

Alex, honestly, Iā€™ve been following the tutorials, and a few things seem broken. I donā€™t know if this was all purely developed for a windows PowerShell/visual code environment, but live servers are usually primarily Ubuntu or another Linux distro, so no visual code or studio. When I run yarn install on your self-hosted migration server and react client, I get a tonne of dependency warnings, and I have to run the build I need to do so with the --ignore-engines flag, and Iā€™m on an up to date Ubuntu 20.04 server so Iā€™m not sure whatā€™s going on there. Is this only for people running a server on their own PC with Windows? If so thatā€™s pretty weak.

Iā€™ve got walletconnect working for connection with eth wallet, so at least my Metaverse is usable now, but that runs out of the box without a self hosted server running.

I mean, even the tutorials are mixed up, sometimes the keys and server urls are in ā€˜single quotesā€™, and sometimes theyā€™re not, so I find that messy to follow. Iā€™ve got my api key and appID fine, I can get the server running, but no connection to the unity webGL build. And am I running the self-hosted server AND client server? Because the client server (react example) doesnā€™t seem to finish starting up when running the hosted server. I can see both servers taking up memory with the top command. Are they just using to much resources? Is it an issue of me having ssl certificates? I donā€™t even know where to start. And you havenā€™t even asked me to look at and send you any logsā€¦ Arenā€™t there logs to debug this shit?
Please help manā€¦

Hi !
I am trying to integrate Web3auth to Unity using moralis.
Any suggestion on how to do would be gold ! :slight_smile:
Thanks a lot !

Yes please !
How to integrate using moralis for unity ?

Thanks a lot !