Ethereum Unity3D Boilerplate Questions

@dgoodrich how big is a Number in the database? Should it be used to store information on wallet balance?

I’m assuming that a Number is essentially the same as in JS, a 64-bit floating point value.

What’s the best way to deal with cryptocurrency balance using Moralis?

1 Like

Hi David,

I’ve been focused on other tasks for some days now but I remember everything was smooth with the SDK.

Today I’m going to update to 1.0.2 to check all the new features/fixes and continue with the process. Also, I need to record a video for the Unity Developer position you guys have available and I will make it about this project. Wish me luck :slight_smile:

Best,

David

2 Likes

You probably already know that a contract stores wei value as a 256bit string. DB cannot handle a number this large and so wei balances are stored in the DB as a string. Of course you cannot do sorting aggregation, etc. on this value as a number.

The Moralis Nitro update provides a way to store the wei as 128bit number (and also capture the whole precision as a 256 bit string). Nitro is still in beta phase but would be worth checking out.

Hope this helps.

BTW, did the fix I sent you earlier help you get past the cloud function validation issue?

Regards,

David

1 Like

Yes the fix did work! This new question is actually what came out due to the validation going through!

Is Moralis Nitro essentially the beta phase for the next stage of improvements which can be accessed starting from the free tier?

Also, I went on Discord and found that the way people were handling string balances was by using Moralis.Units.Token(str, decimals) to convert the string into a BigNumber for use. However, the typescript API marks it as returning a string and not a BigNumber, and somehow even though I have the BigNumber package I’m not able to use new BigNumber(str).

1 Like

Just checked, it looks like the server doesn’t understand what a BigNumber is. Whenever I try to use it with or without importing the type, it throws this error:


  ERROR  || 2022-01-14 05:25:04
Failed running cloud function putWalletWasActiveInInterval for user TMxzXlbYaRxsQ1u3jT0uLXXX with:
  Input: {"signal":true}
  Error: {"message":"Cannot read properties of undefined (reading 'Token')","code":141}
1 Like

The BN library is available through Moralis Web3. Please see this forum question

Regards,

David

1 Like

Somehow it’s not detecting this method!

Could you suggest a relevant thread for my Cloud Code questions?

1 Like

I did not find one that was a good fit so it will best to create a new thread for this.

Regards,

David

New thread for JS SDK issues: Problems with current implementation of Moralis Cloud Code

1 Like

I have followed all the instructions but why when I want to play the demo scene it crashes

Do you mean the Demo scene crashes or Unity3D IDE crashes? Please copy the error that is showing in the log and post it in this thread. The image above does not appear to show the exception.

Thank you,

David

Hey @dgoodrich I received feedback from a dev in the ETHGlobal NFTHack competition on the ResolveAddress API and seems like he gets an error on it:

ApiException: Error calling ResolveAddress: {"code":141,"error":"Invalid function: \"resolveAddress\""}

and his code is like this

Resolve result = MoralisInterface.GetClient().Web3Api.Resolve.ResolveAddress(domain);

Not sure if there’s any problem there or something that he might miss, but if you found something, let me know :raised_hands:

1 Like

@YosephKS,

Can you send me the domain as well? Did the user try this in the admin panel as well?

Thank you,

David

Hey @dgoodrich I am working on a WebGL game. Is it possible to use the web wallets to connect?

1 Like

Hello, you can but it is tricky. The default Wallet Connect / Unity package does not support this so I am working on a custom solution. I am looking at This Project as a solution for us.

Regards,

David

@YosephKS,

Maybe the user needs to update their server?

I ran the example via the Unity SDK:

var result = MoralisInterface.GetClient().Web3Api.Resolve.ResolveAddress("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
Debug.Log($"{result}");

and result was

{
  "name": "vitalik.eth"
}

as expected.

Regards,

David

1 Like

Ohhh I see cool, sorry didn’t saw you message was taking a bit of break. Seems like you already message the user directly as well :raised_hands:

1 Like

@dgoodrich I’m enjoying SDK v1.0.2.

I would like exactly ONE “Hero” subscription to exist and to live as long as the Unity play session. By default, they last longer. Suggestions?

Perhaps I could call RemoveSubscriptions when unity OnDestroy fires, but that is probably too “late” if called as the session ends. I did not try yet.

For code-separation preference I created class MoralisLiveQueryCallbacksForHero : MoralisLiveQueryCallbacks<Hero> which I don’t believe causes any issues.

I tried to call RemoveSubscriptions before AddSubscription as shown…

MoralisLiveQueryCallbacksForHero callbacks = new MoralisLiveQueryCallbacksForHero();
MoralisQuery<Hero> moralisQuery = MoralisInterface.GetClient().Query<Hero>();
MoralisLiveQueryController.RemoveSubscriptions("Hero");
MoralisLiveQueryController.AddSubscription<Hero>("Hero", moralisQuery, callbacks);

But still get the result per image when the Unity play session starts (for the 5th time in this example)

1 Like

Is the “5” above is the Request Id from the MoralisLiveQueryClient instance? I would guess so since this is the Subscription created message. The RequestID is a static var in the MoralisLiveQueryClient that is only used as an application instance identifier to send to the back end.

Q. What build are you running? If WebGL let me know - nothing below may apply.

Q. Are you seeing multiple Subscription Created messages for a single subscription?

Q. Does

Mean that “Play” is froma cold game start or, the game is still running but reset?

The MoralisLiveQueryController is coded so that when the app closes, it automatically unsubscribes all subscriptions. Like wise, when the app (mainly for mobile) goes to sleep it unsubscribes and then re-subscribes on awake. This is to avoid web-socket errors on mobile caused by the app going to sleep.

Please let me know. I will get a chance to re-try this process this afternoon.

Thank you,

David

I use code from the SDK Examples of…

OnSubscribedEvent += ((requestId) => { Debug.Log($"{Title}: Subscription {requestId} created."); });

Now I see that I had misread the Debug log output. I see now that there is no issue. I withdraw my question. Thanks for the prompt help.

To answer your q’s…

  • I’m targeting standalone Windows
  • The output I’m seeing in a play session is completely captured in the screenshot of my related post
  • I’m using the Unity editor’s ‘Play’ to start a play session and the Unity editor’s ‘Stop’ button to end a play session
1 Like