Ethereum Unity3D Boilerplate Questions

@SamR,

For your first question - you helped me find another issue to correct :slight_smile:

I was going to suggest you create a subscription and monitor the close event. However currently when you create a subscription and disable the network it throws an un expected exception.

For now you I would say call MoralisInterface.GetClient().UserFromSession(user.sessionToken); This will re-load the user object from the server, if the internet is available this will return the user object.

I will create an issue in Github for the LiveQuery issue described above.

Regards,

David

Thatā€™s an excellent general Unity tip and an adequate workaround. Ideally, the MoralisSDK provides a solution for us ā€” so we have a bool of ā€˜both internet AND moralis work now?ā€™ not just a bool of ā€˜internet works now?ā€™.

@dgoodrich the project is missing asmdefs. Should I make a pull request for adding these over?

1 Like

@dgoodrich thereā€™s code in Examples that WalletConnectSharp and WalletConnect.Unity requires. Please move those packages.

Thereā€™s also duplicate code in WalletConnectSharp.Unity/Editor and WalletConnectSharp.Unity/EditorTools.

I also found a possible reason for cyclic dependency reference between WalletConnectSharp.Unity and the Moralis folder assuming that asmdefs are defined at the top level of each of those folders: WalletSelectItem is part of the Moralis folder but should technically be in WalletConnectSharp.Unity.

1 Like

The asmdef file is in MoralisWeb3ApiSdk/WalletConnectSharp.Unity/Network/Client

Are you refering to the dependanceis in the Examples\Packages folder?

I will look into this.

Do you see the asmdef file in any folder other than MoralisWeb3ApiSdk/WalletConnectSharp.Unity/Network/Client?

Yes. In the YouTube video introducing the boilerplate, you mentioned that Example can be safely removed/not imported while the others are required. However, at the moment this is not the case.

From the looks of it those contents should be in the DLLs folder.

Apart from UniTask, no, I added a bunch of asmdefs myself because the code I work with uses them extensively.

Specifically, I added an asmdef in each of these folders: Moralis, WalletConnectSharp\WalletConnectSharp.Core, WalletConnectSharp.Unity.
Iā€™m also aware of the one in the location you provided because I was linking each of these asmdefs up that way.

EDIT: at the moment Iā€™ve put an asmdef at the root of the MoralisWeb3ApiSdk folder and linked up the required inner asmdefs correctly. For the purpose of my code, I can use this now, without modifying any of the scripts (except for deleting the duplicate script from WalletConnectSharp.Unity\EditorTools ā€“ I prefer following the Unity convention of using Editor instead).

My point was that WalletSelectItem was being referenced by WalletConnectSharp.Unity from Moralis which doesnā€™t make sense from a modular standpoint.

Iā€™m trying to make a UPM package for local use which incorporates the Moralis boilerplate minus the Example and its scenes (UPM does not support putting scenes in packages), with a bunch of asmdefs for linking with the rest of my codebase.

Other Issues

BTW does the boilerplate package make changes to TextMeshPro? I see that it is included along with the rest of the package contents, which is expected because Unity packages all dependencies together.

Iā€™m also seeing some .cs.bak files in the project, unsure if that should be kept around?

Is it possible to currently work with IL2CPP with this project? I found this GitHub issue about not being able to find HttpUtility when using .NET Framework 4.x.

I can make a pull request if you need it!

1 Like

Hi David,
Iā€™m currently trying out the webGL build of the demo from commit 7138dfb97bbe32984bb3222470a318590a74c460
and it looks like itā€™s doing the same kind of ā€œflowā€ as on PC - i.e. asking to scan the QR code. Is that how itā€™s supposed to work? I would assume the webGL build would connect (or ask to connect) to metamask or some other browser wallet plugin?

2 Likes

I will add an issue to Github for the dependancies in Examples to be moved out of Examples.

It does not. TextMeshPro is used as is.

No. I will add an entry to .gitignore.

The Unity uses IL2CPP for the WebGL to yes. The HttpUtility reference will be removed as it is used in only one place and seems to cause a lot issues for users.

Thak you for you help.

Regards,

David

1 Like

I saw that the Liberation Sans font of TextMeshPro gets modified by the one present in the package.

1 Like

I apologize for any frustration this is causing. This is the default behaviour provided by the Wallet Connect Unity package. I do have a modification in the works so that WebGL calls the browser wallet but honestly it is still in early development.

Regards,

David

1 Like

@Vivraan,

Could you provide the locaion of this change? I do not recall modifying TextMeshPro.

Thank you,

David

It should be the Liberation Sans SDF asset itself. The colour is changed to yellow?

For 1.0.2 of course.

1 Like

Ah, The color was changed in the properties of the menu object in the demo scene. This change is for the demo only. Removing this change may change the way the demo looks but will not change the way the demo works. Feel free to change this in your app.

Regards,

David

1 Like

How exactly should I parse objects returned by cloud functions?

Currently Iā€™m doing something like this:

try
{
    return await MoralisInterface.GetClient().Cloud
        .RunAsync<PutRequestResponse>(
            CfNamePutWalletWasActiveInInterval,
            new Dictionary<string, object>
                { ["signal"] = wasActive })
        .AsUniTask();
}
catch (MoralisFailureException e)
{
#if UNITY_EDITOR || DEVELOPMENT_BUILD
    Debug.LogError($"Moralis SDK encountered an error: {e}");
#endif
    throw;
}

where

[Serializable]
protected struct PutRequestResponse
{
    public bool valid;
}

is the response objectā€™s type.

However I just want the function to return true or false, not a JSON key-value pair?

In the current case Iā€™m expecting that my response must look like

return {
    "valid": true
};

in the JS.

1 Like

Also, when Iā€™m passing the validation requireUser: true to a cloud function, what exactly gets stored in request.user?

1 Like

@vivraan,

The Cloud.RunAsync will return T. So you can do a couple of things.

  1. Change the current code from:
return await MoralisInterface.GetClient().Cloud
        .RunAsync<PutRequestResponse> ... ;

to

PutRequestResponse resp = await MoralisInterface.GetClient().Cloud
        .RunAsync<PutRequestResponse> ... ;
return resp.valid;
  1. If you own the Cloud Function change it to return the bool directly and change the code to:
 return await MoralisInterface.GetClient().Cloud
        .RunAsync<bool> ... ;

Thoughts?

David

The second thing makes perfect sense. Iā€™ll do just that and be more careful of bombarding you with questions next time! :sweat_smile:

1 Like

Under the hood the user.sessionToken is automatically being sent with the cloud function request as a header (X-Parse-Session-Token). The backend takes this and passes it to the cloud funtion.

Parse uses this to retrieve the user object to pass to the cloud function.

Please see the docs section for Cloud functions for more information.

Regards,

David

No worries. Glad you are using the SDK and I want everyone who does to be successful. I want to make this as easy to use and as bullet proof as I can. It has been challenging and there is a way to go yet. Every problem reported / question asked helps to reach the goal faster and let me know what to concentrate on.

Keep up the good work!

David

1 Like

Is there a way in VS Code to get type information of all the required SDK entities?

I see that there are a few Typescript examples around that I can use, but is it possible with JS too?

Most of my questions are related to data types of parameters and their contents, so a user manual would be greatly helpful: Iā€™m having trouble autocompleting Moralis functions on VS Code, and so far I donā€™t think Iā€™ve got the IDE to understand that moralis is already installed via npm install -g moralis. Somehow, npm install --save-dev moralis returns an error saying it couldnā€™t install Logger?

1 Like