Ethereum Unity3D Boilerplate Questions

1: in your Youtube channel i just saw 1 video about Unity, did you have a full SDK or API for unity as well as React or other languages?

Yes, the full SDK (other than Plugins - this is coming soon) is available for Unity3D. Moralis also offers the full SDK in JavaScript, React, and React Native.

2: You have a server. What happens when the server shuts down ? so in this case our Dapp is not Dapp! and doesnā€™t work. Right?

Moralis has layers of servers distributed across the globe so a complete outage is very unlikely.

3: if you support Unity, what Version is good for working with metamask or other wallets in a game? For example Mobile version or OpenGL version?

Any version of Unity3D, 2020.3 and newer. The platforms should all work with the same wallets. The SDK utilizes Wallet Connect so any wallet compatible with Wallet connect can be used. That being said we have noticed that Metamask sometimes has issues communicating with Wallet Connect (we do know that Wallet Connect and Metamask are actively working on this). Due to this we usually test with other wallets.

Hope this helps. Please let me know if you have any other questions.

Regards,

David

So far I understand from the code base that I can execute Cloud functions from Unity but I see no means to deploy cloud functions. Maybe I have to use JS for that.

1 Like

Thanks for asking, yes, Moralis Cloud Functions are supported by the oralis / Unity SDK. The newest version of the boilerplate demonstrates this in the TokenListController.cs file.

Here is the code snippet that shows how to call a cloud funtion:

// Field(s) for the cloud function.
IDictionary<string, object> pars = new Dictionary<string, object>();

pars.Add("url", token.Thumbnail);

ResourceResponse resourceResponse = await MoralisInterface.GetClient().Cloud.RunAsync<ResourceResponse>("loadResource", pars);

The code for the Cloud Function being called, ā€œloadResourceā€, is in the Boilerplate README.

Please let me know if you have any other questions.

Regards,

David

1 Like

You can add Cloud functions directly in your Moralis Server or by using the CLI (correct this is Javascript)

Regards,

David

1 Like

Please check out the Cloud Functions doc page for more information about using CLI to deploy Cloud Functions.

@dgoodrich I had posted a comment a while back on YouTube where you introduced the Unity package.

There Iā€™d said this:

Iā€™d really appreciate if the Moralis package was compatible with UPM for convenience. The Example directory could be part of Example Assets deployed once the package is installed. This also makes it easier to clone the project once and simply update by pulling from a stable branch or commit every time a release is available, and having the package included from the Package Manager.

1 Like

I am currently working with Unity to publish to the Asset Store. Once that is done you will be able to use Package Manager to perform updates. It is all a process :slight_smile:

Regards,

David

2 Likes

One more question that popped up is: how do I upload data to Moralis for use in a database, which will be read off by an oracle on a smart contract?

1 Like

You can find sample code to save data to the Moralis Database in the bloilerplat ReadMe here.

If you want an Oracle to read the data you probably want to set up a Cloud Function to front the data.

If I have misunderstood you question please let me know.

Thank you,

David

In my use case, I have a database that I can interact with from the client app and a smart contract.
The client app sends some information to the server, which is then used to update the database and compute a certain reward.
The contract then queries that database, retrieves the amount to reward, and airdrops the given amount of tokens to the client.

Itā€™s not the Moralis.Web3Api that is missing; itā€™s
Assets/MoralisWeb3ApiSdk/Moralis/Moralis.WebGL/Moralis.Web3Api/Api
that is missing from git (strange that itā€™s the only one missing?)

1 Like

ah - weird. My apologies I will get that fixed!

@enoonmai,

Thank you for reporting that. Cause was a .gitignore for Android API. This also filtered out the new WebGL API folder. Issue is fixed and checked in.

Regards,

David

awesome thanks! :smile:

1 Like

https://github.com/SamuelAsherRivello/Intro_To_Unity_Crypto/ is public. All sublinks, no.

Iā€™m on ā€œMoralis / Unity3D Asset Package v1.0.2ā€. Couple questionsā€¦

  1. How do you recommend to handle casual internet connectivity? Which method can ask ā€œIs the internet connection to Moralis backend working?ā€ The MoralisInterface.IsLoggedIn() is not an adequate proxy. It returns true when I have zero wifi (which itself is not a bug). But the method name will likely lead to developersā€™ confusion. Ideally, Iā€™d like a sync method with previous result, async method seeking up-to-date result, and a callback which fires whenever connectivity changes.
  2. Does the API support deletion of custom objects? If so, how? I see much commented out code, so I assume this is not supported yet.
1 Like

Give this a try: Unity - Scripting API: Application.internetReachability (unity3d.com)

@SamR,

Thank you for pointing this out.

For #2 the answer is yes and no. Looking at the code I had an implementation at one point and in one of the many re-writes I failed to re-implement the ā€œDeleteā€ option directly on the object. A miss on my part.

That being said, for now you can call the underlying service:

await MoralisInterface.GetClient().ServiceHub.ObjectService.DeleteAsync([OBJECT], user.sessionToken);

I will create an issue in GitHub to expose the DeleteAsync method on both the Client and the base MoralisObject.

Regards,

David

I have opened issues #13 & #14 in GitHub for this issue.if you want to follow.

@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