Integrate Godot and Moralis for NFT Games
By Hideki Ishiguro at
Recently, I found the ChainSafe Gaming SDK for Unity.
It's amazing for creating Dapps or NFT games.
However, I personally like Godot not Unity - I think that there are pros and cons, but at least for 2D games, my personal preference - so I decided to integrate Godot and Moralis (an awesome platform for Dapps or NFT Games).
This article is for HTML5 Games Only by the way.
And a detailed explanation of Godot and Moralis is differenct from the main point of here so I'll omit it. If you're curious, please see the official website.
1. Create a new project on Godot
Open the Godot, create a new project. For HTML5 game, recommended the OpenGL ES 2.0.
Next, create a new scene and add a new Button and Label, then save it.
In addition, enter "Login" to the text field in the Button and "Sample text." to the Label.
Then, Assign a new script to the Scene and add pressed() signal in the Button.
2. Import the Moralis SDK on Godot
In Godot, go to the Project -> Export... -> Add... -> HTML5.
Add the following code to the "Head Include".
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script> <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
3. Implement the Moralis Auth in script
Assign a new script file to the Scene and write code.
The whole code is below.
After that, set the values of the Server Url and App Id of your Moralis Server in the Scene.
You can see the above values in the Moralis Server Details. If you can't see, you need to create the Moralis account and server.
Click the Project -> Export... -> Export Project.
Create a new folder named "html5" in the project folder. And the file name should be "index.html".
Then uncheck "Export With Debug".
By the way, set the current scene to the main scene in the project settings as follows:
Finally, we can run this awesome game which only authenticate the Moralis. Open the terminal and enter the followings:
cd <GODOT-PROJECT-FOLDER>/html5 python -m http.server 8000
On your favirote browser, enter "localhost:8000" in the URL bar.
Then you should see the login screen.
When you click the "Login" button, the MetaMask popup will open to login. If you logged in successfully, the sample text will change to your eth address. And the button's text will change to "Logout".
This time, I explained about the Moralis authentication only.
If possible, I would like to make a Godot Moralis Addon.
But before that, the intelligent Moralis Team may make it.