Unreal 5 Get Web3 Data
Introduction
This tutorial shows you how to connect an Unreal game to a Moralis backend, in this case hosted on AWS Lambda. We will retrieve a wallet's native balance and its NFTs.\nBelow we provide a sample game to set everything up in a few minutes.
Prerequisites
- Complete AWS Lambda integration.
- Install Unreal Engine 5.1 .
- Install VaRest plugin to Unreal Engine 5.1.
Open sample game
Go to GitHub and clone/download the repository.
After downloading the project, launch Unreal Engine 5.1 and under RECENT PROJECTS, choose Browse:
Search for the .uproject
file and open it:
The Plugins window should automatically open but if not, go to the top toolbar and choose Edit --> Plugins:
Search for VaRest, enable the checkbox and close the Plugins window:
As stated in the prerequisites, you need to have this plugin previously installed. We will use it to call our Moralis API endpoints hosted in AWS Lambda.
Setting up
On the editor, click the blueprint icon and choose Open Level Blueprint:
This is the blueprint holding most of the logic of this sample game.
Zoom out to visualize and locate 4 important areas:
Manage input
No need to do any action here. Just informative.
Apart from enabling and disabling the player's input, here we get the wallet address
and the chain ID
from the text input fields when the START button is clicked and we save them as variables:
Construct request body
No need to do any action here. Just informative.
What interests us in this tutorial is to know how do we call an API endpoint. In this case we want to call the getNativeBalance and getWalletNfts endpoints hosted in our Express AWS Lambda App. These endpoints need the address and the chain as request body parameters so here we construct the request and we set it as a variable:
Get Native Balance
Add the getNativeBalance endpoint URL to the URL field. You can get it following the instructions here:
Get Wallet NFTs
Add the getWalletNfts endpoint URL to the URL field. You can get it following the instructions here:
Saving changes
Click Compile and then the Save icon:
Play the game
On the editor, choose Play:
Enter a wallet address and a chain ID and choose START:
In this tutorial, we enter 80001
as chain ID but here you can check all the chains that Moralis supports.
Also make sure to enter an address that holds some NFTs to see them on the game.
On the left side we can see our NFTs displayed and our Native balance on the right side:
You've completed the Moralis & Unreal Engine 5 integration tutorial.