DEV Community

Discussion on: Integrate Godot and Moralis for NFT Games

Collapse
 
hideckies profile image
hideckies

Hi, thanks!

If you want to get balance using getNativeBalance, you can write as follows:

var _callback_executed = JavaScript.create_callback(self, "_on_executed")

func getNativeBalance():
    moralis.Web3API.account.getNativeBalance().then(_callback_executed)

func _on_executed(args):
    print(args[0].balance)
Enter fullscreen mode Exit fullscreen mode

Implementing async-await with Godot can be quite hassle, but we should probably be able to implement most of Moralis functions.

By the way, currently I'm developing Godot Moralis Plugin. When it's done, I'm going to add the repo in this article.

Collapse
 
iogamesus profile image
IOGamesUS

Awesome, thank you. I'm making everything work through the browser since I assumed you had to in order to connect your Metamask, so I got it to work printing in the console using:

var obj = JavaScript.get_interface("Object")
$Panel/CenterContainer/HBoxContainer/Balance.text = "Current balance: " + obj.values(args[0])[0]
Enter fullscreen mode Exit fullscreen mode

...but I probably could've done args[0].balance like your code and been a little cleaner.

Perhaps you've tested the getNFTs function before as well? I can't seem to get anything in the response, despite having NFTs on the address I'm checking.

Looking forward to seeing that Plugin. Please do update when you're ready for other eyes on it! I'd love to help.

Thread Thread
 
hideckies profile image
hideckies

I've not tested getNFTs yet, so I don't know but I'll try it sometime.

Yeah it may take some time, but I will do it;>

Thread Thread
 
wterich4 profile image
Wüterich

Hey, did u get it to work?