Web3 Game Developer in 2024 Roadmap: Unity, Smart Contracts, Connect a Wallet [Full Course]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone Shan watas here and Welcome to our web 3 game developer course where we'll be learning how to implement web 3 tools and functionality to Unity games using third web's Unity SDK in this course we'll learn how to implement features like connecting a wallet for a user to our game interacting with smart contracts on chain and how to build and run our games on platforms like web native and mobile devices there are a few things I want to point out before we jump into this course one we aren't going to to be building a game itself in unity we will provide you with an example game or you can use an existing game that you have in unity and what we're going to be showing you is how to use third webs Unity SDK and how to implement those features and functionalities into your existing games we also won't be going over the basic tools of unity although this course will be very simple and basic where you can follow step by-step even if you aren't really familiar with unity again we'll be providing you with an example game that you can clone for yourself and use to follow along in this course or you can use an existing unity game that you already have we've also broken down this course into easy to follow sections all the time Stamps will be down below in the description so if you want to jump ahead to a section that you want to learn a little bit more about or you need to skip back and rewatch a section to relearn it all those links again will be down in the description below but an overview of what we're going to be covering in this course we'll first go over what is web 3 gaming how does it differ from our traditional games that we're used to right now and and what are really the concepts that are introduced with blockchain technology we'll then go over the example game that we're going to be providing you for this course again you can feel free to use your own game if you already have one but we do have an example endless Runner game we'll go over the game how it works and we'll also show you how to clone it so that again you can follow along with this course by using that we'll then start implementing and integrating web three functionalities into our game the first thing we'll cover is connecting a wallet to our game we'll go through through a few different methods on how you can do this first through a simple connect wallet button where a user can connect familiar wallets like a metamask coinbase wallet or any wallet connect wallet we'll then show you how to implement something called embedded wallet which is a tool that we have here at third web which allows a user to sign in with social logins or an email and then finally we'll show you a combination of embedded wallets with something called smart wallet which is your account abstraction wallet or an ERC 4337 wallet and we can really show you how we can enhance the user experience with that wallet combination we'll then jump into the smart contract section of our course we'll first take a look at erc20 smart contracts we'll learn how to deploy our very own erc20 smart contract which we can use for things like in-game currencies and then we'll show you how to interact with that erc20 contract within your unity game we'll then jump into ERC 721 contracts we'll showcase how you can deploy your very own ERC 721 contract these nfts can be used for things like player accounts or maybe even access passes that token gate a user from using your game we'll also show you how to interact and Implement those nfts into your unity game using third webs Unity SDK next we'll go over ERC 1155 smart contracts we'll deploy our very own ERC 1155 smart contracts which you can use for like in-game assets and again we'll show you how you can interact with them inside of your unity game last in our smart contracts we'll go over custom Smart contracts not only can you use standardized contracts like ear 20 721 and 1155 but you can also deploy and create your very own custom Smart contracts that you want to create for your own web 3 games for this example we'll build our very own leaderboard contract where we'll be able to create a custom contract that keeps track and Maps a user's wallet address to their scores and we can then display their ranking and scores in our game after those smart contracts we'll go over something called an erc20 pay Master now we'll cover what pay masters are when we go over the embedded wallet and smart wallet combination but in that section we'll take a look at how we can create something called an erc20 pay master and how that can enhance the user experience even more for our web 3 games and finally after we have built our web 3 game in unity we'll show you how to build and run this game on web native platforms and mobile devices and that is what we're going to be covering in this web 3 game developer course again all the time stamps to what I just went over will be down in the description below so we made it easy for you to navigate throughout this course if you want to watch certain sections come back to it fast forward to other sections again you can reference all those time stamps down below so with all of that being said we're going to jump into our next section where we're going to cover what is web 3 gaming the concept and overview of web3 gaming and how it differs from our traditional gaming that we're familiar with today so in this section we're going to talk about what is web 3 gaming how is it similar to the traditional gaming that we're familiar with today and how it differs with the new introduction of blockchain Technology we'll start off with the similarity part because it's very short web 3 gaming is very similar to the traditional games that we are used to today they look and feel the same way when you interact with them many web 3 games nowadays actually mask and hide a lot of the blockchain interactions that you would normally deal with on a web 3 application so the games that you love to play like sport games racing firstperson shooter battle cards strategic games all of those are really the same concept behind them the gameplay feels the same but where things really differ is when you introduce blockchain technology to this game and really what blockchain technology introduces is the ability for players to now have ownership over their assets so if we look at traditional games today you normally create an account and you can buy some in-game assets so say you want to buy certain skins or you want to buy certain game assets like uh weapons or whatever it may be inside of the game that you're playing a user has an account that they create with the game and then they purchase those items now those items live within the account that lives within that game and really the game owners or the game developers have the right to that account which means that if you do something bad or you do something that will ban you from the game you don't have control whether or not that game blocks your account bans your account and restricts you access from it and now you take a look at web 3 games when you create an account you're really what you're doing is signing in with a wallet now that wallet for most web 3 games you have the full access and ownership rights to that account on top of all that in-game assets and items even in-game currencies you can create tokens nfts and utilize things like smart contracts where if you have an in-game currency you can make this an erc20 token which means that I now own this erc20 token within my account which is my wallet and I can easily send that out to another wallet if I want to if I have an ERC 721 nft I can use this as maybe an access pass or something so if my wallet owns this access pass I get access to certain things in the game I can then send this access pass or sell that access pass to someone else and transfer it to their wallet or account and we can take a look at examples like ERC 1155 nfts where we can utilize these nfts as in-game items maybe in a game I'm collecting certain materials and everything I can treat these as nfts as well and again I can buy and sell these nfts and I have full right to now transfer these items and do what I please with these items on top of ownership blockchain technology also allows interruptibility between games because the data of these assets are on chain and that data is public and accessible by anyone blockchain into three games introduces interruptibility between multiple games this means if I have a game asset in one game as say I get a skin or something in one game uh because it's on chain I can access that data in another game and I can still access the same skin in a different game so this whole idea of a metaverse or interruptibility between multiple games which web through game introduces and makes it really easy to do because of blockchain Technology with the use of blockchain also introduces is some of the unique features that you get with blockchains and one of those features being immutable data on chain with a blockchain no one has the ability to manipulate or change or delete the data that is on the blockchain this means that we have full transparency of the things that are happening within this game so a game developer can't just go dropping you know rare items to certain people or you know funding certain accounts with millions and millions of in-game currencies all that information will be public for everyone to see so we can take a look at you know where assets are being traded from who's trading what assets who's earning certain things and how they earned it and this makes for a better experience user- wise because again this data and everything is public on the blockchain and there is no way to again manipulate this data because of how blockchains work so to sum it all up web 3 gaming really brings the power back to the players gives ownership back to them over their accounts and in-game assets it also adds another layer of features to games that we already know including the ability to have interruptable assets between multiple games we're already seeing a bunch of amazing games being launched utilizing third web's Unity SDK we'll link down in the description below a few of those games that you can go and check out to see what is really possible with web 3 gaming so that was a quick overview of of what is web 3 gaming and what does web 3 gaming really bring to the table now let's jump into the course and let's actually start building out our very own web 3 game in the next section we're going to go over the endless Runner game example that we're going to be using throughout this course we'll go through an overview of what the game looks like how it works also show you how to clone the repo of this game so that you can use this game and follow along throughout the course again we're not going to build the game from scratch we will quickly go over it and provide it to you so that you can follow along or feel free to use your own unity game that you already have and you can follow the same implementations that we're going to be doing hey everyone in this section we're going to go over the endless Runner example game that we're going to be using as an example throughout this course now this game here we do actually have a live demo of so if you do want to try it out on your browser we'll link that down in description below but I have the final version here opened up in my Unity editor and we're just going to run this really quick and go through the game so you have an idea of the game that we are going to be using so I'm going to hit run here we're allowing a user to sign in with a social login so you can use Google Apple or Facebook to log into our game this is utilizing embedded wallets now we're going to go over all the different ways you can connect a wallet the game demo that we are looking at right now just has embedded wallets enabled so let's sign in with Google here it actually opens up a browser window for us to sign in we'll head back to our game now you can see here that we are now back in our game and we can start playing it so again it's an endless Runner game where obstacles will appear we can use our keys here to navigate through the obstacles and you can see our travel distance and score is increasing so it's a very simple game that we're going to be using as our example but we will add be adding some of the web 3 components like being able to connect a wallet interacting with smart contracts and everything to this so if we hit a obstacle here you can see our distance traveled we have our ranking here we'll be able to submit our ranking which is actually going to use a leaderboard contract something that we're going to be building out in this course a custom Smart contract uh we can hit submit what that's going to do is submit our score and give us our ranking here on where we rank amongst other people playing the game we're getting a transaction here it's successful and my score is ranked 13 so from there we can then restart the game and we can sign back in and start playing the game again we have our canvas here which is going to hold our image and our panel login which is going to have the buttons to log in with Google Apple or Facebook we have our blockchain manager UI manager and obstacle manager here which is going to have our script for generating those obstacles that appear our UI manager here is going to be our UI manager for things like the game over screen and everything and then we have our blockchain manager here which is going to have the script that we're going to add all of our blockchain functionality to so again a quick overview of the game that way you have an idea of what we're going to be using throughout this course and what we're going to be building again you don't have to use this game as an example what we go through in this course you'll be able to apply and Implement into any unity game so if you do want to use your own unity game you can do that as well in the next video we're going to go over how you can clone a version of this game we have a branch where we remove moved all the blockchain aspects out of it so what we'll be doing throughout the course is actually utilizing that branch and adding the blockchain functionality and being able to interact with our smart contracts adding a connect wallet button and everything so stick around for the next video if you want to learn how to do that you can skip that video if you're going to be using your own Unity project and you can skip to the following video where we'll show you how to import the unity SDK into an existing unity game so in this video here we're going to go over you can clone the example endless Runner game that we'll be using throughout this course so right over here we have a GitHub repo of the game we do have a bran here called blockchain list which we've removed all the blockchain aspects out of the game and you'll be able to use this as a starting template and follow along throughout the course as we add things like connecting wallets and being able to interact with smart contracts so to clone this version here we're just going to open up our terminal and we're going to run uh git clone DB we're going to choose the blockchain list Branch here we're going to provide it with our ghub repo link and then I'm going to name this here Our Endless Runner example and we'll run that that will clone the end that will clone the branch for the blockchain list version of our game here and once that is done we will open that up in unity now you'll also need to install Unity as well that is what we're going to be using throughout this course if you don't have Unity we'll link down in the description below unity's documentations and guides on how you can install it once that is done we'll open up our Unity Hub here so our Unity Hub what we'll do is add a project we're going to look for Our Endless Runner example and we'll open that we'll give it a moment for it to grab Our Endless Runner game and it will open it up in our Unity editor and once that opens up you can see here we we can go into our project folder down here head on over to scenes and we'll open up the main scene right over here so you can see we have the game we don't have any of the actual web 3 components like a connect wallet or anything that's going to interact with the blockchain now one thing about this template it does already have the third web Unity SDK imported into the game now this is because we are using some UI components and everything from that third web package within the game so we didn't want to break that but in the next video we'll go over how to actually import the unity package into a new game so if you do want to learn more about how to do that and you're building a game from scratch and you want to install it watch the next video If you're looking to follow along with this all you need to do is clone this Branch here and we'll be good to go so again this Branch here all the web 3 stuff is abstracted away so if we hit play here and we run our app we can just start playing our app here and again and it's uh if we hit a wall it's just going to have restart it's not going to have any of the leaderboard functionality we don't need to connect a wallet or anything in the beginning as well so again this is going to be the template here that you can clone and what we're going to be using throughout the course as we slowly add in the web 3 components to it in the next video again we're going to go over how you can download and import the third web Unity SDK into a brand new unity game okay in this video we're going to go over how to to install and import the third web Unity SDK into a brand new unity game so if you're not following along with the example endless Runner game that we showed in the last video and you're using your own unity game or you're starting a brand new unity game this is going to show you how you can import the unity SDK so this is our Unity docs here and you can read through this it does have an installation guide and everything you can follow here all we need to do though is head on over to get the latest version of our SDK so open this up here as I'm making this video uh version 4.7.5 is our latest version and all we're going to do is download the third web Unity SDK which is this Unity package right over here so we'll click on that it'll download and the next thing we can do is open up our Unity Hub and create a new game so in our Unity Hub here we can create a new project you can select the base of your project here I'm just going to leave it as 3D core here we'll name this as uh my we'll just say my web 3 game you can name it whatever you want I'm not going to connect this to Unity Cloud here but we're going to create a new Unity project or if you have a Unity project already just open up that Unity project so right over here it's going to open up our Unity editor now uh we'll wait till this finishes running all the scripts okay once that's done again the assets tab import package and we can import a custom package here with that open we'll find our Unity SDK that we downloaded and hit open you'll then have a import window that shows here we can just select all here this is going to be all the items that we're going to import from the third web Unity SDK we're going to hit import and once that's installed you see that you'll get a third web folder here which will provide all of our prefabs and everything that we will use throughout of this course so again this is for importing the unity SDK to your existing or brand new unity game if you're using the endless Runner example that we provide for this course that game already has the third web Unity SDK imported so you don't need to go through this process but we did want to share how to do this if you are again implementing this into an existing game or creating a new game you should now have an example endless Runner game template that you can use or be using your own unity game and have the third web Unity SD imported from here we'll be utilizing those games and we'll be walking through how to implement the different web 3 components tools and features into your unity game the next section we're going to cover on how to connect a wallet to your unity game we're going to go through the different methods that you can connect a wallet from connecting wallets like metamask wallet coinbase wallet or wallet connect wallets to using third web tools like embedded wallet and smart wallets so again make sure that you have a game with the third web Unity SDK installed and we'll head on over to the next section hey everyone so in this section we're going to start building and adding in web 3 functionality and everything to our unity game now again we're going to be using thir webs Unity SDK and we will be using our example endless runer game throughout this course now if you skipped ahead to this section and you didn't check out the last section we cloned a version of Our Endless Runner game that had all the web three components stripped out from it and we also went over how you can install the third web Unity SDK into your unity game whether it's this example game or a unity game of your own that you're going to be using so if you didn't do that section or you haven't gone through and you don't have a unity game with the third web Unity SDK I suggest going back to those sections there getting a game or the endless Runner game example and having the third web Unity SD installed now in this particular section we're going to go over something called the third web manager and this is going to be an important key part to building your Unity games using third web so with that being said let's jump on the computer here and let's get started so again I have my endless Runner game here uh again all there's no web three components or aspects in this game if you cloned the um blockchain lless version of it now what we are going to be doing is adding in the third web manager so we come back to our Unity docs here and again the unity docs will be linked down in the description below if you want to just click on that to navigate here really quick on the left hand navigation we're going to go to the third web manager now a third web manager is a mono behavior that provides a convenient and customizable way to initiate and manage the third web SDK in your unity game now behavior is a base class in unity that allows scripts to attach to game objects and this is going to provide you access to your game events input physics all the things that you would need to normally configure within your unity game and it has life cycle callbacks like update and start so depending when your game is loaded or your scene is loaded you can trigger certain callbacks within that as well this is actually going to the third manager is actually going to be a prefab and all we need to do is add that prefab into our scene so you can see here the prefab can be found in our third web core prefabs and then we will find the third web manager so let's head back to our Unity editor here and all we're going to do is find our third web folder we're going to go to core we're going to go to prefabs and right over here we're going to have the third web manager now I'm going to click on that prefab here and you can see on the right hand side in our inspector we have our third web manager prefab asset all we need to do is drag that into our scene you do need a third web manager within your scene each one of your scenes that you're going to need to interact with the third web Unity SDK so again we're just going to have this here and we're going to go through this inspector panel here which goes through all of the core things that the third web manager allows you to control so the first part here is going to be your general settings and in your general settings this is going to be things like your active chain so we can set the active chain of our game here so maybe in my case I want it to be Mumbai so we can set it by just setting it to Mumbai that way when we connect to our game the default chain is going to be the Mumbai Network you can add supported chains here so if if you want to support other chains within your game as well you can put it in here you can just hit the minus to take them away you can add them on and so forth and so forth so let's just say for this one here we only want to support the the Mumbai chain so I'm going to remove all of this here actually move mum by to the top and I'm going to remove everything else out of here so I only have by Chain here with the chain ID 80,000 And1 we also have an area for our client ID so all we need to do is grab a third web API key grab our client ID provide it right in here and that's going to provide the client ID throughout the whole third web Unity SDK so heading to my third web dashboard once you have a wallet connected you can come to the settings tab and in there you have your API keys and you can just copy your client ID for the API key you want to use come in here and paste that in you have options to override the bundle ID you can also initialize this on awake so basically once your scene is loaded it will initialize the third ofb SDK or you can choose to initiate it manually if you choose to do so uh you can also show the debug logs or not uh we're just going to leave that on here so we can also look at the logs to see what's happening and that does it for general settings now you also have app metadata and all this information if we come back to our docs it's all within here as well so within the app metadata this section lets you define how your app appears in wallet providers like metamask wallet connect or any other type of wallet you can come here you can configure the app name the app description and you can also provide it with the app uh URL and app icon too if you have app icons for it now we're not going to touch any of this here but just know that you can come in here and put in all that information and metadata for your app storage options here you have an area where you can put in an ipfs Gateway URL if you want to use ipfs storage we have open Zeppelin Defender options this is going to be if you want to use open Zeppelin Defender for things like gasless transactions you can create an open Zeppelin Defender um basically a relayer where you want to fund it and have that relayer take care of the gas for you you just need to put in your relayer url here and the forwarder address below that is your wallet connction options this is where you can provide the information about your wallet connect project ID if you're using things like wallet connect and finally down here at the bottom this is going to be smart wallet options so if you are utilizing account abstraction or third web's smart wallets within your unity game you can just put in the factory address of the account Factory smart contract here that's going to be generating the smart wallets for you and then you can toggle on if you want to allow gasless transactions or not in optional Fields here you can also add in your own bundler URL your own pay Master URL or your own entry point address too so if you want a little bit more customization you can add those things in down here at the bottom there is a danger zone these things are areas that you can customize if we hit reveal the wallet connect metamask and embedded wallet prefabs this is if you want to customize the UI components for these wallet connect options now by default you'll be using the ones provided by the third RB Unity SDK you can modify those prefabs too if you want to or you can provide your own prefab in here if you choose to do so and there you have it that is a quick run through of the third web manager again you need that within your scene in order to use the third web Unity SDK now if we take a quick look back at docs all we need to do to access the SDK is once we have the third web manager set up we can access the instance of the third web manager just by getting the third web manager. instance. SDK and from there we can start using all the things in the unity SDK to interact and communicate with the blockchain that does it for this section here just a quick overview of the third web manager it is very important and it again allows us access to start using the third web Unity SDK within our unity game in the next section of videos we're going to go over how to connect a wallet to your unity game we're going to go over how to connect your usual blockchain wallets like metamask or wallet connect wallets we'll also go over how to use something called embedded wallets which will allow you to sign in with social loging or email and we'll also learn about a combination of embedded wallets plus smart wallets which is account abstraction and how those two can go hand inand and really create a seamless user interface for your users in your web 3 game hey everyone so in this section we're going to go over adding a connect wallet button to our unity game now we're going to add a simple connect wallet button where you'll be able to log in with something like a metamask wallet now third webs Unity SDK does have a pre-made connect wallet prefab which we are going to be using and showing in later sections we'll show you how you can create your own custom UI and still add the wallet connect features to your own UI that you created so that being said let's jump on the computer here and let's see how we can connect a wallet to our unity game so here in my Unity editor we're going to add a connect wallet button to our unity game here now I'm going to create a sample example canvas here just to use while we add in a connect wallet button in the final version of this game we're going to be creating our own custom login screen but we just want to show you how you can easily and simply add a connect wallet button into a unity game so in my hierarchy here I'm going to right click and I'm going to create a UI and I'm going to select canvas right and I'm going to just name this uh example canvas and I'm just going to move this right up our below our main canvas here so in our example canvas uh I'm going to add the connect wallet prefab so we already have a prefab that is easy you just click and drag it in and it gives you a connect wallet button so coming down here in our examples folder there's a prefabs folder and in here you'll see a prefab for The Connect wallet button so you can see here in the insector we have prefab connect wallet I'm just going to click and drag this into our example canvas into the example canvas here and with that example canvas let me just come to our scene here and let me just click on prefab example let just click on our prefab connect wallet I'm going to connect the anchors here and I'm just going to drag it to fit our canvas here there we go I'm also going to select our canvas and I'm going to adjust the size here to scale with screen size and I'm just going to make this uh width or the xaxis 1920 by 1080 and we'll set match to [Music] 0.75 all right so if you look at our game here we now have a connect wallet button right here in the top right and that's how simple it is to add a connect wallet button to your unity game now I'm going to do something really quick here because if I test this out and I start playing my game um we're going to start playing the game already and then if we try to connect our wallet we may not be able to select it and we don't want to hit something accidentally and then the game over screen is going to cover our wallet here so what I'm going to do here is I'm just going to disable our player so I'm going to come over to the character game object here I'm going to open this a little bit uh I'm going to open right click on the character manager script and edit the script so right here is our character manager script here I'm just going to scroll down to the uh start here and I'm going to uh toggle that is enabled here to uh false and save that and come back to our game let that compile and you can see here when I start my game again uh we're not going to move or anything and now we can test out this connect wallet button so let me open this up here so when we select our connect wallet button you can see that we are brought up with our different options here let me just make this a little bigger and we have the ability to sign in with email metamask coinbase wallet wallet connect hyperplay we have injected wallet as well or we can continue as guests and use something called a local wallet you can read up about the different types of wallets in our documentations so what we're going to do here is look at metamask so if I click metamask here it's actually going to bring me a QR code uh this is going to be so that we can connect with a metamask on our mobile device device so if I take my mobile phone right over here and I scan that QR code it's going to open up the metamask app on my phone and I'll have to select connect and connect my metamask wallet to the game here so I have to switch Network it's asking me to switch to the proper Network and there we go I connected and you can see right up here we are now connected to the game here this is the metamask wallet that is connected and the network here is on Mumbai and from here I can also disconnect my wallet so if I hit log out it just disconnects me I can come back here and I can come back in and then connect my wallet back again you can see up here that we have email now this is going to be embedded wallet we're going to go a little bit more in depth in this in the next section uh but again we can add embedded wallets very simply and easily into here but we're not going to get into that now let's take a look at the connect wallet prefab so let me open up the inspector here on the side let me stop this and let's take a look at the connect wallet prefab here so select the prefab we can look at the inspector here and we can look at some of the different things that the prefab has to offer to us we can see the enabled wallets here so let's just say I only want to enable metamask I can come over here and I can take away all these other wallets and I only want to support metamask I can leave that there we also have the option down here if you are using ERC 4337 or account abstraction compatible smart wallets you can check this off and it will utilize the wallet that the user selects as the eoa wallet to the smart wallet and it'll use the account Factory that we set up in the third web manager which is right over here and that will allow you to connect to a Smart wallet or a smart contract wallet instead so if you were using that you would just toggle that off and it would utilize that um smart wallet option from your third web manager you also have events here so you can create your own function for you know when your scene starts you can add in different functions here you have on connection requested so when you request a connection you can add your own functionality here you can add functionality when a wallet is connected you can trigger your own callback function here for unconnected uh for connection errors and for when you are disconnected as well you can do the same thing for on switch so if they switch networks or something you can also create your own callback functions there down at the very bottom here you have UI components for things like your embedded wallet your metamask coinbase wallet Etc so again you can add in your own prefabs for those UI components or you can edit the prefabs that they have already so if you click on it here it'll show you where that prefab is we can come over to the embedded button here and we can then configure and change some of the things like the color and everything of the button coming back to the inspector here you can also change things like the email input the export button wallet images so you have a little bit more so you have that customization to customize the UI component of the connect wallet button you don't have to use the default one and how it's designed here we give you all that customization where you can come in here and mess around with the UI and design it how you want to match your game with all of that said now that we you know took away some of the wallets and everything we can run this game again let me just make this a little bigger we hit connect wallet and you can see here we only have our metamask option hit the metamask option it's going to bring up the QR code for us to scan we can scan it with our phone I'll do it one more time for an example here that will open up the metamask app on my device I can connect and once I'm connected there you go you can see we now have my wallet connected which is the metamask wallet so again you can see how quick and easy it is to add a connect wallet button to your unity game in the next section we're going to be going over the embedded wallet which is the ability to sign in with a social login or email all right in this section we're going to go over another way to connect a wallet for a user to your web 3 game that way is through something called embedded wallets now embedded wallets allows a user to sign in with social logins or an email address and essentially a wallet will be generated for them we can take a look at our docs here really quick uh I'm under the unity SDK docs under wallet interactions here uh we can take a look at the prefab for our connect wallet prefab again we went through this in the last section we were able to connect with something like a metamask wallet we also saw the option to sign in with something like email now email is what is going to be offered through embedded Wallet not only do you get to sign in with email like I said but also social logins things like Google Facebook Apple ID uh you can sign in with all those different things there now under wallet providers you also have we can take a look at embedded wallets here and you can see here we can actually create our own UI components and allow someone to connect their wallet utilizing like their email we can create our own email input login button all of that or we can have them log in with an ooth 2 which is something like Google Apple Facebook you can also bring your own o here if you are part of our growth plan or up you can utilize your own oth and you can do any type of authentication flow uh such as JWT and you can allow anyone to authorize with anything your own custom off you can do any type of other social login typee of off flow uh you can build your own uh we do have support Google Facebook and apple right now out of the box so this is something that we're going to utilize when we build our own custom UI we'll show you how you can connect a wallet using these social logins but again this is what is going to allow you now why would someone want to use an embedded wallet like this right why would you want to allow a user to sign in with a social login or email let's take a look back at our Unity editor here and if I play our game so in the last section we went over how to connect something like a metamask wallet which you can do do but you have to you know I have to take on my phone I have to scan a QR code if I'm using like coinbase wallet or something I need to be on a browser I need to have the wallet app actually installed on my device too if I'm doing it on mobile and it's another extra step that you have to do in order to get a user to start playing your game so what embedded wallet allows us to do is oh let me add embedded wallet here really quick uh let me come back here we'll come into our inspector here we're going to add a second we'll make this first element here we're going to make it not hyperplay embedded wallet here let we just close this down we'll run this game again there we go we'll connect wallet and there we go we have our email and you can select any social login so we can select something like Google it's going to open up our Google signin page here I can select an email that I want to sign in with and again this flow is much easier um to a user who doesn't need to necessarily leave into a different application they can confirm and sign in with social login like they would any other type of game or any type of other authentification route that they go through in like a web 2 application so you can see here we can close this tab head back to our game and we are now connected with a wallet you see here this is the wallet that was generated for me using embedded wallets and I am now connected to our game now here's one thing this wallet that I have signed in with does have funds I actually funded this wallet I sent some mtic over to it and that's why I have some funds in it now what happens with this is a new wallet say someone is brand new to our game they signed in for the very first time they're not going to have funds in this wallet and why is that important or why is that something that we should take note of it's because again in order to interact with the blockchain you need funds in order to cover the gas fees in order to execute transactions we'll be able to connect a wallet to our game but whenever a user wants to interact with the blockchain they're not going to be able to because they don't have the funds in their wallet to actually interact and execute those transactions on the blockchain so with that we can do a couple things we can one we can go to our let me just uh stop this here we can come to our hierarchy we can go under third web manager here and we can use open Zeppelin Defender now we do have a way where you can use open Zeppelin Defender create a relayer and this relayer basically takes care of the gas you fund the relayer in open Zeppelin and the funds come out of that relayer the other option is we have Smart wallets and smart wallets are ERC 4337 or account abstraction wallets and when we create this smart wallet we have options for gases transactions which you're still going to have to cover the gas as the developer side but you have a lot more features and functionalities that you can do with smart wallets now we're not going to get too deep into smart wallets or account abstraction in this course here but we did create another course where we went over how account abstraction Works what account abstraction is and different types of benefits and features that you get out of using something like this and one of those big things is that these smart wallets are smart contracts so we can create a logic to them we can also create gases transactions later on in this course we're going to go over something called an erc20 pay master and a pay Master is what's used to cover the gas cost and fees with things like ERC 4337 wallets but what we'll be able to do is we can create our own gas token basically a user can pay with our own custom token while we handle the gas again we're going to go over that stuff a little bit later on in this course of course if you want to jump over to it you can check the time stamps down below but again smart wallets and ERC 4337 wallets just allow a little bit more customization for us to make the user experience of playing a web 3 game really simple so again you can use just embedded wallets yourself but a user will still have to fund that wallet if they ever need to interact with the blockchain in the next section in the next video we're going to go over the combination of embedded wallets with smart wallets and with that combination we're going to cover the features and benefits of it like we just went over where you can have gasless transactions and that way your user never really needs to one create a wallet or fund the wallet with crypto funds because they'll be able to interact with the game utilizing the combination of those two so that's all for this video we'll jump on to that in the next section all right so in this section we're going to learn how to use the combination of embedded wallets with third web smart wallets this is a combination of being able to sign in with a social login or email and have an ERC 4337 wallet generated for the user and in the last section we went over some of the benefits and everything that you get with this combination but I did want to go over it just again in this video here so if we connect with a embedded wallet which is allowing a user to sign in with an email or social login again it generates a wallet for them but the wallet has no funds and in order for them to start interacting with the blockchain in your game they're going to need some sort of funds in their wallet to execute those transactions it's still another step that a user would have to use that requires them to know some sort of knowledge about cryptocurrency or blockchain in order to get funds into the wallet what if we want to create an experience where we abstract away all the web three complexities out of the game and that's where the combination of embedded wallets with smart wallets come in you don't have to use the combination of embedded wallets or smart wallets you can use any type of wallet as the EA wallet to the account abstraction wallet but what this will allow us to do is again abstract away all the complexity so you don't need a metamask wallet coinbase wallet wallet connect wallet you just sign in with an email or social login and you now have a smart wallet to use now we're not going to go too into depth about what account abstraction is or what smart wallets are but we did create a course if you want to learn a little bit more about what they are I we'll link that down in the description below you can go ahead and check that out but what we are going to do is come back to our documentations here in the navigation tabs here we're going to come to contracts we're going to hit deploy contract here and up in the popular section you should see uh something called account Factory if you don't see it there you can scroll down we have Smart wallets here and then there is the account Factory right over here so we'll select account of factory you can see this is for ERC 4337 account Factory contracts and we're going to hit deploy now now for this under the networking chains you can deploy a deterministic address basically you'll have the same contract address across all chains I don't want that for this but if you are looking to maybe support different chains using smart wallets you may want to do that I'm going to uncheck it I'm just going to deploy a account Factory contract that's only going to work on Mumbai here so I'm going to uncheck that select my networker chain I'm using Mumbai and I'm going to hit deploy now I'm going to confirm that transaction to deploy our smart contract then I'm going to sign the signature request to add it to our contract dashboard once that is done we'll be brought to our contract here you can see our account Factory contract and all we're going to do is copy our account Factory contract address come back to the unity editor and Under The Factory address here I'm going to paste in the contract now I do want to enable gasless transactions so I'm also going to make sure that is checked off and that's how simple and easy it is to set up smart wallets with your web 3 game now we're not completely done just yet uh I have to come back to the prefab here uh for our connect wallet and if you remember uh we do need to toggle off that we are going to use Smart wallets now before I do that I'm just going to allow email here really quick let me just um wallet providers I'm going to get rid of metamask I'm only going to put in uh embedded wallets here and let's just run this really quick now I don't have Smart wallets enabled I'm just running embedded wallets really quick to show something so I'm going to run this game here we're going to sign in you can see we have email here so I'm going to sign in with the email I'm going to select Google and you can see right over here my email or my embedded wallet that I signed in with ends in 8 a96 now that's the embedded wallet connected to the application now okay so I'm going to sign out here I'm going to activate and enable use Smart wallets right over here in the connect wallet prefab oh let me sorry let me stop that uh check that off again so again using smart wallets now that I have that checked off going to run this now when I sign in I'm going to select email I'm going to select Google you can see we're signing in with our embedded wallet here and what that will next do is then connect us to a Smart wallet so if I look here now my new wallet address here is 43 EA you can see a little new symbol here this is a smart contract wallet or an account abstraction wallet created with our embedded wallet as the admin and that is then going to sign into our game we'll then use that login to connect to a Smart wallet and we'll show you how you can build your own custom UI to create your own custom connect flow for your web 3 games all right in this video and section we're going to be building our very own custom UI for logging in and connecting a wallet for our user now in the previous videos we went over the connect wallet prefab which gives you a pre-built UI component that you can just click and drag into your unity game and with some configurations you can enable things like logging in or connecting a metamask wallet we did connecting a user with an embedded wallet which allows them to sign in with a social login or email and we also did a combination of embedded wallets with smart wallets and enabled features like gases transactions and that allows a user to again connect a wallet without having to create their own wallet they just to sign in with their email and they don't need to fund the wallet because again we're going to be handling all the cost of transactions on the developer end with the smart wallet utilizing account abstraction and something called like a pay master in this one we're going to create our very own login flow so maybe you don't want to use the connect wallet prefab and maybe you want to build or implement this into your own login flow or UI components within your game this is what we're going to go over so the first thing we're going to do here is we're going to disable our exam example canvas here so the canvas that we created with the connect wallet button we're just going to click on it come into the inspector and uncheck and disable that there we're then going to come over to this canvas main you should have it if you cloned our repo here but we're just going to toggle this on and within this canvas main we have a login panel or a panel login here uh you're going to click on that and you're going to enable that so we already have a pre-built UI for you we're not going to go through over how to build the UI although I will do a quick run through on what this is so we have a canvas here we have some titling and some backgrounds here uh in this panel login which is this panel here we have a label which says log into your game account and then we have three buttons uh each of the buttons are for a social login so Google Apple ID or Facebook so again you can implement this into your own login flow this is just the example one that we give within our example game and what we're going to be using essentially if you click on one of these three buttons here you'll be prompted to sign in with Google Apple or Facebook so what we're going to do is build in our own script to handle that login flow so in our hierarchy here I'm going to rightclick and I am going to create an empty and I'm going to call this here my Block Chain manager I'm going put that right over my third web manager and in this blockchain manager object I'm going to come into the inspector add a component we're going to add a new script here called the blockchain manager script so I'm just going to create that there you go and then we'll have a script here that we can now edit and use so once we have that script created I'm just going to right click on it and hit edit script this should bring up a your blockchain manager script within your code editor here and what I'm first going to do is up here we're going to oops I'm just going to highlight this and we're going to going to be using a few different things here so we're going to make sure we have systems system collections system collections generic systems threading task third web Unity engine and unity engine event all right and then down here you can see we have our blockchain manager script which is a mono behavior and we have some start and update functions here I'm just going to delete them for now and what we're going to do is create our variables here so the first one I'm going to create is a public Unity event which is going to be a string and we're going to call this on logged in so we're going to call this event here and this event is going to trigger when we log in so we're going to use that to trigger uh some other functionality within our game then we're going to collect the users address so we're going to get a public string here called address we'll be able to uh use this address outside of this script here uh but we're going to make sure that the private or the set is set to private because we are going to be setting the address within this script and this script only and then we're going to create a public static uh which is going to be our blockchain manager script and instance and the same thing here we're going to be able to use this within other scripts but only set that within this specific script and then to set that blockchain manager script here we're going to create a private void awake and we're just going to make sure that we only have one instance of this blockchain manager script running so if instance is null we create an instance here but if there is an instance already then we will destroy the current instance and make sure that we only have one instance running so next thing we're going to do is create the function to allow a user to connect using those social logins now we're going to allow them to choose the social login they want to connect with we'll create an embedded wallet with that social login we'll then set that social or that embedded wallet as the EA or the admin wallet for a smart wallet using third web so I'm going to come down here we're going to create a function so this is going to be a public async function here and this is going to be called login and this is going to take a string and the string is going to be what off provider is the user signing in with so are they signing in with uh Google are they signing in with Facebook or are they signing in with apple we'll then create a variable which is going to be an O provider uh oops and O and Capal P here provider and this is just going to be called our provider here and by default we are going to set the off provider to Google but we will switch that off provider accordingly to the string that we provide this function so if it's Google we keep the Au provide or the provider as Google if it is Apple we will switch it to Apple and then if it is Facebook we will switch it on over to Facebook so once we have the off provider set we can create a connection here and connect the users's wallet so we're going to create a variable here called connection and in here we're going to create a new wallet connection and for this new wallet connection we need to provide it with who the provider is in this case the provider for this new wallet connection isn't going to be our embedded wallet it's going to be a new smart wallet so we're going to say wallet provider. smart wallet then we choose the chain that we are going to be connecting to which is going to be the chain ID and in this case it is going to be uh Mumbai so 800001 then we choose the personal wallet because we are doing a connection with a smart wallet we set the personal wallet here to a wallet provider dot embedded wallet and that's going to use our embedded wallet that we created up here as the personal wallet to the smart wallet that we are connecting we'll then set the O options here and we're going to create a new o options and the O options off provider is going to be the provider that we have selected or that the user is selecting to log in with so that is our new wallet connection setup and then we can provide then we can set the address uh which is the variable that we created up here again we're going to be storing the connected wallet address into it so this address here we're going to await and then we can get our third web manager here and through that we can get an instance of our manager and we can use our SDK to then call connect and we will Connect using the wallet connection that we created right up here now once that wallet is connected we're going to get an address and if you remember we created an event called on logged in right over here so we're going to then call that event on logged in and we're going to invoke it and we're going to give it and provide our address now with that we now can use this event and see when this event is triggered and we can come on over to our character manager file the one that we went to earlier um remember we turned on is enabled to false we're going to change this back to True here and what we're going to do here is you should have some commented out code uh but we're going to get our blockchain manager script make sure it's spelled correctly and we're going to get an instance of it and we're going to get to check if on logged in we're going to add a listener and if there is an address then we are then changing is input enabled to true so we can actually just comment this last one out here uh because this event listener here will then trigger and set that to True here and what that will do is once our what this is doing is when we start our game it's not going to start the game until someone has signed in and until it retrieves an address from the event so it's listening to the event once we sign in and get an address then it triggers then it that's the is input enabled true and then the game starts to play so that is our function there so let's set up this function with our login panel now so let's come back to our game here uh looks like we have an error here um blockchain third web SDK does not contain definition connect oh uh SDK sorry about that so in the SDK uh under wallet we then have our lowercase W sorry under wallet and then we have the connect through there so we just need to make sure we had wallet there now when I come over to this login panel we're going to head over to the buttons here so we'll first set up the Google button so I'm just going to enlarge the inspector just a bit and if I come down to the bottom here uh we see the onclick now I'm going to just delete these on clicks here and what we're going to do is add some on clicks so right over here I am out the any Ras that what we currently had I'm going to add a new one I'm going to drag in our blockchain manager script here and I'm going to select here from the blockchain manager script the login function now the login here is going to take a string and in this case it's going to be Google and once we click that we should also disable the main canvas so I'm going to drag in the main canvas here we're going to go game object set app active here we're going to leave it unchecked and then the game canvas here I'm going to drag oops I'm going to add one more and then I'm going to drag in the game canvas here and we're going to set the game object set active and we're going to make sure it is checked off so again what this is doing on the on click is we're going to run our login function by passing it the string Google so it knows that Google is the provider that we are setting then I'm going to close CL out the canvas main which is this one right here so we're going to close that out and then we are going to make sure that we turn on the game canvas so we're closing out this canvas here and making sure that the game canvas is enabled so with that uh we're just going to test it out with Google here and we'll do the rest to the remaining buttons as well so I'm just going to open this up a little bit more again we're going to run our game so right over here we are presented with our login panel you can see we can't play our game or anything and our game isn't being played our score isn't being updated none of that is happening until we log in so if we hit Google and we log in you can see we have logged in and now we can start playing so once we start playing we can start playing here uh and then we lose and then there you go we can restart it restarts back to the beginning we can log back in it's going to connect us again with our smart wallet and then we start playing the game and there you go we created our own custom login flow over here if we stop running our game so now what we can do is again we can set that same thing up for Apple here uh we can come back here we just will delete those on clicks uh we can add on again another onclick function we slide in our blockchain manager script we select that and we set the login here and this time we provide it with Apple so we know which one to do and then we create two more here and we can then get the main canvas game object SE active make sure it's unchecked and then the game canvas we can come to game object set active and make sure it is checked off and you can do that for all the buttons there so there you have it again we created our very own custom UI our own custom connect flow utilizing embedded wallets uh so our social logins connecting it to a Smart wallet and then being able to start our game once a wallet is connected and in the next section of the course what we're going to be doing is start to interact with smart contracts we're going to be deploying our very own erc2 ERC 721 and 1155 smart contracts we'll use those contracts for different areas of our game so depending on what our score is we can collect erc20 tokens equivalent to our score will then token gate our game and create an erc721 nft pass that you need to have in order to play our game and then depending on your score you can get different rewards and those rewards will be ERC 1155 nfts a quick example and we'll show you how to deploy those contracts how they can be used in your game and how to interact and read data from the contracts as well again time stamps for everything are down below in the description so if you need to rewatch some of the connect flow things you can rewatch some of that if you want to fast forward into the next section you can head on over there too so that does it for our connect section hopefully you took away many ways that you can connect a wallet to your web 3 game and with that let's jump on over to the smart contract section hey everyone in these next few sections we're going to be learning how to deploy our very own smart contracts and how to interact with them within our unity game we'll be deploying ourselves an erc20 smart contract for tokens and rewards that we can earn in the game we'll then also deploy an erc721 contract which will act as a pass so we're going to require that a user has one of those nfts in order to even play our game and then we'll also deploy an ERC 1155 contract which will act as rewards So based on how well the player plays they can earn rewards and then finally we'll build our very own custom Smart contract which will will be a leaderboard and depending on the player's score we'll show them their Rank and everything and they can view all this information in the game over screen once they lose the game and can't play anymore the game over screen will appear with all of this information so in this first section we're going to be deploying an erc20 token and implementing that into our game how we're going to be using the erc2 token is whatever the user score is at the end of playing our game they'll be able to claim the amount of tokens equivalent to their their score so the very first thing we're going to do in this video is deploy ourselves an erc20 smart contract so you're going to head on over to third web's dashboard here we'll link this down in the description you're going to connect your wallet and then up here in the tabs you're going to head on over to contracts next you're going to deploy yourself a contract and for this example here we're going to deploy ourselves an erc2 token drop contract now the token drop contract is just a claimable erc20 token so this drop section here you'll see token drop so again this is going to be a Tok erc20 token that we can claim in this tutorial and video this token will be able to be claimed by anyone so that means if anyone has access to your contract or anything they'll be able to claim it as well if you do want to set it up where only a specific wallet or maybe you want to restrict who can actually claim these tokens you can look into something called Signature minting or you can also utilize third web's engine as well well we're not going to go over those things in this video specifically but if we ever do release those videos that go over it we'll make sure to link it in this video in the description but again do keep that in mind that what we're going to be going over these tokens can be claimed by anyone who has access to the contract but what we do want to go over is how to implement how do we write and execute functions to these contracts and how do we read data from it so back to this we're going to deploy ourselves a token drop contract I'm going to hit deploy now I'm going to call this our Unity token we're going to call this Unity here for our symbol you can add an image a description down at the bottom here you're going to select your network or chain you want to deploy to so you can hit that drop down you can select any evm compatible network we support any evm compatible blockchain uh for this tutorial I'm already deployed and everything to Mumbai so I'm going to select Mumbai you'll select your own networker chain there then I'm going to hit deploy now we'll get a trans action that appears we'll confirm that to deploy our contract then we'll get a signature request to add it to our dashboard so we'll go ahead and sign that there we go we have successfully deployed an erc20 contract now there's one more thing we need to do on the leftand navigation we need to head over to claim conditions and we're going to add a claim condition phase now these claim conditions are where we can add the restrictions and everything to claim these tokens again we're going to keep it really simple here and we're going to just set this to public so we're not limiting the amount of tokens there are we're not charging for these tokens and anyone can claim any amount of tokens that they want if they have access to this contract so I'm just going to save that claim phase here we'll confirm that transaction to save it and there you go we now have our claim condition set so coming back to the overview page here we have our contract address and we have deployed our very own erc20 token again we're going to be using this token so a user can claim the amount of tokens equivalent to the score that they get in the game that does it for this section in the next section we are going to go over how to interact and execute the claim function from this contract within our unity game all right welcome to the next section in this section we're going to take the erc20 token smart contract that we deployed in the last section and we're going to implement it into our unity game and again we're going to be making it so that a user can collect the same amount of token equivalent to the score that they got so we'll come on over here uh we do have our contract that we just deployed here what I'm going to do is head on over to our Unity editor right here and I'm going to come over to the game over screen here so there is a canvas here for the game over I'm going to turn that on I'm going to turn off right now the game canvas and the main canvas there we go just so we see what the game over screen will look like and what we're going to do here is just add a UI component in here so I'm just going to drop this down and I'm going to right click and add a UI component and we're going to add a button here and this button is going to be our claim button and the text here if you hit the drop down of the claim button you can edit the text object here and we're just going to say uh claim tokens I'm going to come back up to this claim button head on over to the scenes here and we're just going to make this button a bit larger here there we go we go and we're going to take the restart button oh sorry game over panel let's drop that uh button into the game over panel here uh and then this try again button we're going to just drop it down here to the bottom and then we have our claim button here and we'll just drop it down just a little bit so there you go we now have a button and what this button should do is whatever our score is we should be able to hit that claim button and in within our unity game we'll be able to claim the tokens equivalent to the amount of our score so what we're going to do next is actually create the script function uh to claim those tokens so coming to our code editor here I am in my blockchain manager script still if you have closed that out already you can come back over here to your blockchain manager object you can just right click on the script and hit edit script and that should open it up in your code editor so the first thing we're going to do is make references here to our game objects uh which is the button that we created so I'm going to create a uh public and this is going to be for a button and before I do that we have to make sure that we add these two things here cuz we are going to be using TM Pro and unity engine UI uh for the button and the text that we're going to be referencing here so we're going to have a a button here uh we're going to call this our claim token button and then we're also going to have a public text mesh Pro UGI which is going to be our claim token button text and we also need to reference a couple more things so the one thing that we need to make sure that we have a reference to is the current score of our user so we need to know what the score of our user is so that we can claim the that amount of tokens and that score is actually stored in our character manager here so in our character manager we have this distance traveled which is the score or the amount that the user has traveled in the game we want to be able to access this here within our blockchain manager script so I'm going to also create another public this is going to be our game or our character manager and we are going to so character manager is this class right over here and then we want to just call this our character manager reference and then we are going to create our own private string here and call it distance traveled and we're going to make this variable here equal to the distance traveled variable here so those are going to be the four new variables that we create again we're going to be getting a reference to our button to the button text reference to our character manager script so we can get the distance traveled and we're creating a new variable here called a distance traveled with that we're going to create a new void for update now update this is a function that is just going to be called every frame of the game here and what we're going to be doing is setting the distance traveled equal to our game manager reference which is going to be our reference to this game manager script here we're looking for the distance traveled variable which in our game manager script is this distance traveled variable right over here and we're uh the variable you can see is a float so we're going to make sure that we change it to a string and we're going to set that amount to the distance traveled we'll be able to use this variable to set the claim amount of how much of the NF or how much of the token we want to claim so we'll save that there and then we can come down to the bottom here and let's create the function to claim our token so we're going to make a public async void here and this is going to be called claim token and the first thing we're going to do here is we are going to set the text and everything for the button so we're going to set the claim token button text here. text uh and this is going to equal we'll say claiming and what we also want to do is make sure that the button can't be clicked multiple times so we'll set the token button the interactable to false so this way once someone clicks it they won't be able to click it again and repeatedly put through transactions it'll only go through once then we will get our contract that we're going to interact with so we'll create a variable here we'll call this contract and we can get our contract uh first we need to call our third web manager we'll get an instance of our third web manager we'll again call our SDK and within our SDK we have something called get contract and all we need to do is provide this with our contract address so we'll come back to here we'll copy our Unity coin contract address paste that into here and now we can start interacting with this contract so we'll create another variable here called results or just result uh we will then await our contract we can specify because this is a pre-built uh contract from third web we have the ability to say hey this is an erc20 and all we want to do is call the claim to function from this contract here when we get uh later on in this video in the section where we create our own custom contract we'll show you how you can call your very own custom functions from the contract with pre-built ones we within our Unity SDK you can just call these functions here so the claim to function here we need to provide it the address that we want to send the tokens to and the amount so the address is going to be the address of the connected wallet which we get from from our login here we set the address here uh to our address variable right over here and then we have the amount and the amount that they want uh we want the user to be able to collect is the distance traveled so whatever their score was is the amount of tokens that they should collect and then finally at the end we will set the text here to claimed tokens so again a quick run through of our claim token we first created our references to our button the text of the button and we made a reference to our character manager script where we're pulling the data of the distance traveled so we know how much tokens we are going to claim we create our own variable here for distance travel and we set that equal to the distance traveled variable from the character manager script then we created a function to claim the token where we set the text make it we disable the interaction of the button here once someone clicks it we get an instance of our contract we then call the claim to function from that sending the tokens to the address of the connected wallet with the total amount of their distance traveled and then we change the text at the end to claim token so let's come back over to our Unity editor here and what we're going to do is in that canvas game over in the panel game over we'll select our claim button and we'll scroll down and we're going to set the on click here we're going to hit add we're going to drag in our blockchain manager here and we're going to select the function from the blockchain manager called claim token so when we click that button now it should call the claim token function from our script and be able to claim those tokens so let's test this out to see if it works I'm going to click my game over canvas here turn that off I'm going to turn on my game canvas and I'm also going to turn on my canvas main back on again so we look there we go there's our game so I'm going to play and run this game here there you go let's log in with Google we're now logged in you can see my score is going up I can play the game and once we hit one of these obstacles here I can hit one there you go you can see distance traveled 567 now if I hit this claim tokens here oh we didn't set our references give me one sec sorry about that so let's click on our blockchain manager uh remember we set those references to the button and the text and everything uh we need to make sure we set those references so we'll come over here into the canvas game over into the panel we'll get our claim button there we'll set that we'll get the text from our claim button drop that down set that there and then we have our character here which we're going to drag into our character manager reference here because that's where the script of the character is so now that we have those references set let's run this again here there we go we'll sign in with Google once we're signed in we should start seeing our score goal we can play the game and let's just play right here there you go 226 so now if I hit claim token you can see here it is claiming I can't click the button it's disabled we can even check the logs down here the transactions and everything are going through again we are using smart wallets so we're using gasless transactions here so the user doesn't need to pay for the gas it's all being handled on the developer side and right over here you can see claimed tokens in our logs here we actually have the transaction hash of the actual transaction but if we head on over back to our token dashboard and we go to tokens we can see the balance here is there are 226 tokens claimed which is equivalent to the 226 right here which was the player score so we know now that we can claim these tokens but if you do look at our game as of right now we don't have a way of displaying how much tokens this user actually owns so in the next section what we're going to do is show you how you can actually read data from the smart contracts and display it into your game all right and in this section we're going to continue off what we've been doing in the last few sections and we're taking our erc20 contract and we have already been able to create a function and a button to be able to claim the tokens within our unity game now let's create a way for us to actually read the token balance and display it to our user so instead of writing and executing a function how do we actually read data from the contract and display it into our game so in my Unity editor here I'm going to turn off my canvas main again I'm going to turn off my game canvas here and we're going to open up the um and enable the canvas game over where our token button and everything is in there I am going to create a few more UI components so I'm going to right click here under UI we're going to add a text mesh Pro this is just going to be our uh we'll say balance title and I'm just going to put this over our panel here and our balance title if we take that and we go to our screen I'm just going to rise this up and let's just move this around let's make this a bit wider here going to make sure that I Center my text so in the inspector I'll just Center it and I'll just put up here and I'll just write balance right we'll also make that bold and there you go we have our balance title next I'm going to do the same thing I'm just going to actually let's just duplicate this here so take my balance title we'll just right click duplicate and we just have here we'll change this from title to amount and I think yeah so we have our balance amount and we'll drag that down and this text here is going to be we'll say zero we'll make it a bit larger so we'll say 64 and we'll put it right over there so right below so if we look at our game now we see balance and zero and we're basically going to just update this value here by reading data from our smart contract so we have the UI set up right we going to this is where we're going to show our balance now let's come back to our code editor here and what we're going to do here is first uh create a reference to the text that we just created so I'm going to come back up here I'm going to create a public uh this is going to be a text mesh Pro uui it's going to be our token balance amount text and now we can create a function that updates that text so below my claim token function here I am going to create a public async function we're to say void and this is going to be called get token balance and in this function here we're going to get our contract again so I can actually just copy this uh right over here we're going to be doing the same thing we'll get our contract then I'm going to get my balance so say balance and for that we are going to await we have our contract and remember because this is a predeployment we're checking the balance of for the token of our contract that we got up here so once we get that balance back and if we take a look at our documentation here so we'll come back here we take a look at our Unity SDK documentation we can come to contract interactions we can come to erc2 and if I just click on the main erc2 here you can see we get the balance of so we can call the balance of we provide it with the wallet address and in return we're going to get a few different things we get the name of the Val uh token the name the symbol of the token decimal value and we have the display value here and the display value is what we want this is going to convert the amount here into ethers for us and give it to us in a string that we can then display so coming back to my code editor here we're going to take our token balance text amount. text and set it to our balance. display value right and that's going to give us the display value as string and it's going to set that new value as the string within our game so now if I come back to my unity game here let's let that compile right we have to come back to our blockchain manager here we now have that reference space here for our text so we're going to grab the balance amount here and slide that in I just noticed I spelled amount wrong here so let me just take away 1 M there we go so in our blockchain manager we have our balance amount so that text right there is our reference that we're going to be updating so if I run this game here and let's make this a little bit bigger oh sorry let's stop that uh let's turn off our game over screen here let's turn back on our canvas game turn back on our canvas main there we go and we run that one more time right we log in once we get logged in the game's going to start playing our score is going to start going up there you go we can start playing our game and there you go we hit balance died and and our balance still shows zero and I I forgot to add this into our game here so let's come back to our uh script here uh we need to add this into a few different places so the first thing we need to do is we're going to add this into when we log in we want to check the balance so once we get the wallet connected we want to be able to check the balance here so I'm actually going to create a new function here call this uh void and and we'll call this invoke on login and we don't need to provide it that we just need to provide it with the address so we're taking this here so I'm just going to delete this and we're also going to call our get token balance function so we're creating this new function called invoke on login so when we get logged in we will call our Unity event here and we'll get the token balance so in here we're just going to give it invoked logged in and we also want to to make sure that we update that token balance once we claim new tokens as well so down here we'll say get token balance as well so coming back to our unity game let's let that compile one more time we'll run this here so as soon as we log in and our game starts it's actually getting the token balance and setting that text for us already so now we can play our game here there you go so 226 from our previous game here uh distance traveled right here 24 9 so if I hit claim token again it's going to claim 249 tokens it should update our balance here to add 249 to this as well so once our claiming is through you can see down here our transactions are going through we're claiming these tokens on chain through our smart contract that we deployed there we go tokens claimed and now our balance has updated to 475 we can't claim any more tokens because again we've disabled that button there we can restart we can log back in we can play the game and we can start playing again and claim those tokens and our score should then update once again so again this time I got 226 again we'll claim this is going to claim our tokens update our balance and we are now being able to execute and write functions to our smart contract as well as red dat from our smart contract giving us our total token balance that we own in this wallet that we're signed in with so there you go 701 now so that does it for our ERC 20 tokens again we deployed our own smart contract we created a functionality where a user can claim equivalent amount of tokens uh that's equal to their score that they got we're able to claim those tokens we're able to display the token balance in our game in the next section we're going to do something similar but with an ERC 721 nft contract and we're going to treat that nft as an nft pass or a pass in order to play our game and the only way someone can start playing our game is if they own that nft so in a way we're token gating our game to make sure and verify that a user actually owns a specific nft so again if you want to rewatch any of these sections all the time stamps are down below but if you want to join us in for that next section where we're going to be deploying our own nft pass and token getting our game to that nft again time stamps are all down below if you need to go back and forth and rewatch some of these sections hey everyone in this section we're going to be going over deploying our very own ERC 721 nft smart contract in the previous section we deployed an ERC 20 smart contract and we made those tokens claimable and based on how the player did in our game their score would be the amount of erc20 tokens they would be able to claim after the game ended in this section we're going to be using an ERC 721 as a pass or a access token to to be able to play our game so in this case you could basically token gate or block off certain parts of your game and require an nft in order to access what's behind there and we'll be using an ERC 721 to demonstrate this example and in this section we're going to just deploy ourselves our ERC 721 smart contract that we're going to be using and then in the following section we're going to implement the checking of the balance and token gating our game to that nft right here on going computer I am on third web's dashboard I'm going to head on over to the contracts tab here and I'm going to deploy a new contract now for this example of the ERC 721 nft contract that we're going to be using we're actually going to use a open Edition ERC 721 we're not going to use nft drop or nft collection we're going to use open Edition here and essentially what open Edition is it's a open to Mint ERC 721 meaning we don't have to put a uh Supply cap or anything on the nfts although all nfts will share the same metadata so the image description and everything is all going to be the same just the token ID number itself will differ so especially if you are creating a type of pass uh per se uh you can use this contract right over here we'll be able to set the shared metadata for all the nfts minted from this collection and they'll all be the same but they'll be erc721 tokens so I'm going to go to deploy now uh we're going to call this a Unity Game Pass and we'll just give it the symbol of pass and what we're going to do here is come down to the bottom again you can select any network or chain any evm compatible network or chain I deployed my last erc20 onto Mumbai so I'm going to use the Mumbai chain for this uh but you can use any again evm compatible chain just select the drop down search your chain and you can select it then I'm going to hit deploy now we'll confirm the transactions to deploy our contract we'll confirm another transaction to confirm our metadata and then we'll sign the signature request to add it to our dashboard once that's deployed you'll be brought to your contract dashboard here you can see Unity Game Pass and we're going to come over to the leftand navigation go to the nfts and we're going to have to set our nft metadata so in here we can set the pass so we'll just call this a Game Pass here you can select your media I'm not going to add any media I'm not going to display any media in here but you can set the media for your game pass of your actual nft add a description and everything what you set here as the metadata is going to be again the metadata for all nfts minted to this smart contract so we're going to set that metadata here confirm the transaction and there you go we now have our nfts uh metadata Set uh coming back to the left hand navigation we're then going to set a claim condition we're going to add a phase for this tutorial and course I'm going to select public again same as the erc20 token when we select a public claim condition anyone can claim from this smart contract so there is no restrictions or limitations to people claiming from our contract here if you did want to of course put this into a production like game you can use things like signature minting or utilize third web's engine to control who would be actually able to claim these nfts that way if anyone has access to the contract they still need to go through your game in order to claim but again for this tutorial and course we are just going to do a public claim phase here and I'm going to hit save phase we'll get a transaction here and we'll confirm that to save the changes and there you go we now have the claim condition set so coming back to our overview here of our smart contract we have everything set from the nfts metadata and the claim conditions so our ERC 721 smart contract is ready to use in the next section we're going to go over how to actually implement this into our unity game how to check if the person logging in owns The nft Game Pass stopping them from playing the game if they don't own it and how to actually claim the pass within our game so head on over to the next section and again if you need to go back and rewatch anything all the time stamps are down below in the description hey hey everyone in this section we're going to be implementing the ERC 721 smart contract we just deployed in the previous section into our unity game now again a quick overview of what this ERC 721 nft is going to be used for we're treating it like a pass to access our game you can use ERC 721s as a way to token gate or block certain areas of your game and we can check to see if a connected wallet is an actual owner and verify ownership of the nft to see if the player should be able to access those certain parts of the game so again we deployed the ERC 721 contract already now in this section we're going to implement some of the UI and some of the functionality into our unity game so let's jump on to our computer here and get started with that so right over here we have the ERC 721 smart contract that we deployed we're going to be again taking this and using it within our unity game so I'm going to come back to my Unity editor here and what we're going to be doing to uh token gate our game essentially is we need to check to see if a user um owns the nft when they log in so once they log in with their wallet here once we confirm that they have logged in we're going to check the wallet to see if they own the nft now if they don't own the nft we want to prompt them with a section or some UI where they can then claim the nft so we're going to use that example canvas that we created uh for the connect wallet button in the earlier sections I'm going to just turn off uh main canvas here and turn off uh turn on example canvas so you can see we have our connect wallet button in here I'm actually going to open that up I'm going to delete the connect wallet button we no longer need that I'm actually going to come into the canvas main here and I'm going to this panel login I'm going to right click and duplicate it and bring that duplicated version into our example canvas here and what I'm going to do with this uh panel is we'll just call this here our nft claim panel and this is where we're going to create the UI for our nft claim so in that drop down we have the label and this label again this panel is only going to pop up if they don't own the nft so we'll say you don't own a pass and then we're going to present them with a button to then claim the pass so I'm actually going to delete these uh social media buttons here and I'm going to in the panel right click UI components and add another button and this will be our claim pass button and in that claim pass button we'll click into it change the text and over here it'll say claim pass we'll come on over back to our button we'll come to the scene tab here and we can you know make this a little bit bigger move this over here there you go we'll drop it down to the bottom just like that so there you go now when we don't have the pass if we log in it'll say have this button here we can click on it to then claim the nft so that's going to be kind of the UI that we need for our game now we just need to create the functionality to one check the wallet when it's logged in to see if it owns the nft and if they don't we need to be able to prompt this page here and if they do they should be able to just go ahead and access our game so I'm going to turn off example canvas here uh I'm going to turn back on canvas Main and what we're going to do next is again head on over to our blockchain manager uh we're going to edit our script here so we're going to just edit script and that should open up your blockchain manager script into your in your code editor and what we're going to do here is we need to check the balance of the uh connected wallet when the user is logged in so we already have a login function here right uh we are we have this login function here which is when a user selects one of these social logins to log in we create a new wallet connect and then we get the address and we connect the wallet right over here utilizing third web's manager and unity SDK so what we're going to do here is before we invoke the login and Trigger the game to start we want to check if the connected account owns the nft so what we can do here is we can get our contract so we'll say say contract and we are going to get our ERC 721 contract so again we're going to use third web manager. instance. SDK and we're going to use the get Contract now we need to provide it with our contract address so I'll come back here copy my contract address come back in here paste that in now again we do have some extensions here that we can use with third web pre-built contracts so if we come back to our Unity SDK documentations here and we go to contract interactions I can come down to ERC 721 and under erc721 I can use the balance of and this is going to get the wallet's nft balance uh based on the contract that we're getting it from so what I'm going to do here is create a variable called balance and we are going to then await our contract uh we can say this is an ERC 721 contract and we want to call the balance of function and we are providing it with the wallet address of the address that we just set now this is going to give us back if we come here balance of it's going to give us a string of the balance of the nfts that this wallet holds and all we need to do is say if the uh balance equals a string uh zero uh that means the user does not own the nft and what that means is we then need to prompt them to claim the nft but for right now we're just going to uh debug log here not minting nft uh but you don't have a pass yeah so we'll just debug uh that information there uh but we'll say else uh if they do if the balance doesn't equal zero it means that they have the nft and in that case then we can invoke the login and that's going to call this function here which is going to uh trigger our event and get the token balance and everything for uh the logged in user so again we are this is within the login function when we log in a user using our social logins after we connect the wallet and get the address we are checking uh we're getting instance of our contract here we're checking the balance saying hey how much of the nft pass does this address hold if it is equal to zero uh we should see a log here that says you do not have a pass yet and the game shouldn't start but if they do have it it should say Hey you do have it we're going to start the game for you and it should trigger everything as normal so we're going to save that uh we're going to come back to our game here let that compile um let's see uh error invalid expression term I let's oh we added one too much so only be two equals there there we go let that compile so we're going to keep an eye on our logs right over here but if I play my game and run it let's open this up a little bit here and I sign in once we sign in you can see here it is checking and we have a log here that says you do not have a pass yet because this wallet address that we signed in with does not own the nft pass yet uh that is the prompt that we get and you can see here I can't play the game the game isn't starting yet uh and it just says you don't don't have a pass yet so we know that the check is working now we just need to display our panel here right this panel right here um that allows a user to claim the nft so let's head back over to our code editor here we're going to create a reference um here to our uh let's say uh public uh it's our game object uh it's going to be not our login panel but we'll say a claim panel panel and then we also want to build uh the function to claim the nft or mint the nft when that panel appears so we're also going to have to reference our buttons here so we're going to uh similar to how we did the button and text mesh uh Pro here we are going to do the same here with our claim button so we're going to have our claim button and the text of the claim button right over here so I'm going to save that uh before I forget I am going to come back to our Unity editor here I'm going open up our inspector here a little bit under the blockchain manager I'm going to set those different uh references here so the first one is the claim panel uh which is going to be my example canvas here the claim button which is going to be within that example panel uh we have our claim button and then the text of that button I'm going to drop it down one more time grab the text of that button right there so our references and everything are set to the UI components of our game now we can create our functions and toggle on the uh panel here to display so we'll toggle that panel first so right over here where we have the uh debug we are just going to come right here and we are going to take our claim panel. setactive to true so again when we set that to true it is going to display that claim panel so we can test that out actually really quick we'll come back to our game let's run our game here uh if I log in again it's logging in it should say hey we don't have uh the nft so it's going to show you don't want a pass and then again we now need to create the function to claim the pass here but we know our panel and everything is going to show up so now we just need to create that uh function to claim the nft let's come back here let's scroll down to the bottom here and let's create that function so what we're going to do here is create a public async uh void here and this is going to be called a claim nft pass and what we're going to do in this claim nft pass is we're going to set the text of the button here oops uh text uh so the claim button pass button text to claiming we're going to disable the button and check change the claim nft pass button interactable to false we'll then get our contract here uh which we can just uh copy the same thing from up here so get our contract and then we can get the result here we'll store that uh but what we're going to do is await our contract again specify it's an erc721 and then call the claim to function from this and the claim to function we are going to say who we are sending it to which is going to be the address of the connected wallet and then we need to give it the number of or quantity that the person should be claiming in this case it is one so again we can take a look at the documentation here under ERC 721 under claim conditions we're using the claim two right over here so wallet address and then quantity coming back to our code edor once the nft has been claimed we can change the text to say hey claimed the nft pass we'll then have to set the panel to uh active to false so we'll disable the panel cuz you no longer need to see it and then we will rerun the invoked on login function so it will rerun this here to check hey person owns the nft and everything let's log in let's check the token balance and they can then play the game so we'll save that there come back to our Unity editor there we go uh let's run this game here so now again we're going to log in with with our social login it's attempting to log Us in it sees hey we do not own the nft it's going to prompt us up with the panel saying I do not own the pass um we can then claim the pass and actually sorry I have to stop that we didn't add the function to the button so let's come over to the example canvas here under our claim panel and go to the claim button let me enlarge this inspector here on the onclick We'll add a onclick function and then we'll drag in our blockchain manager right over here select function and from the blockchain manager script we are going to uh choose the claim nft pass function so now that we have that Set uh we can then run this again log in it's going to see that we don't own the nft it'll prompt us up with the panel here we can then claim a pass you can see it is claiming so we'll wait for that to go through you can see our logs here the transaction and everything is going through once it goes through it should then rerun that invoke function and allow us to start playing our game there you go game is now starting and we can start playing this game there you go I traveled 222 again this is the functionality from the last sections we can now claim an erc20 token so I can say hey claim that's my current balance within my account I'm going to claim 222 more tokens so once that claim my balance should update and we should see that our tokens have been claimed there you go tokens have been claimed our balance should update 923 we can restart start playing again so now that I have just minted the nft in this last game if I log back in it should just log me in it should start the game for us and there you go we can start playing now and I don't need to Mint the nft pass because I already have one and that does it for this section again we deployed our very own ERC 7 21 nft we use that as a pass to get access to our game and we checked to see if a user has and owns that nft prior to being able to start our game if they don't we prompt them to a claim page where they can still claim the nft within our game again this was an example of how you can utilize ERC 721 as game passes for your game you can utilize ERC 721s in many other ways as well well in the next few sections we're going to go over ERC 1155 tokens and we're going to be creating reward tokens or achievements for our game so head on over to the next section if you want to continue on if you need to rewatch any of the previous sections before again time stamps are all down in the description below hey everyone in this section we are going to continue our use of smart contracts within our unity game and we're going to be focusing on ERC 1155 contracts here in the previous sections we used an ERC 721 as a access pass to play our game we also used an erc20 token as a way to claim tokens equivalent to the score that a player has when they play our game in this section in the next few sections we're going to be implementing an ERC 1155 smart contract and how we're going to be implementing it here is as nft Rewards or nft achievements So based on our player score if they score less than 500 they will get a bronze medal if they score between uh 500 and a th000 they'll get a silver and if they score over a th000 they'll get a gold achievement nft now we just use those numbers just as an example but of course you can configure your achievements differently within your game so what we're going to do in this section is deploy ourselves an ERC 1155 smart contract and set up our nfts for our bronze silver and gold rewards the next section we'll be implementing them into our unity game so let's jump on the computer here and let's deploy our ERC 1155 contract so here on my computer I am on third web's dashboard I'm going to head on over to the contracts tab I'm going to click on deploy contract and I'm going to deploy an addition drop contract now this is a claimable ERC 1155 smart contract and just to quickly go over ERC 1155 tokens are semi funable tokens so I can have just three tokens three nfts bronze silver and gold but I can have multiple owners of each one of those tokens so I can say people can own multiple bronze tokens multiple silver multiple gold tokens so we're going to deploy this contract here I'm going to hit deploy now uh we're going to call this here unity game rewards we'll have the symbol of rewards you can add image description here as well at the bottom we're going to select the networker chain you want to deploy your rewards to you can hit the drop down select any evm compatible network I'm going to be using Mumbai like I have been for this course and I'm going to hit deploy now I'll have a transaction here that appears we'll confirm that transaction to deploy our contract and we'll get a signature request we'll go ahead and sign that to add it to our dashboard there we are our contract has been deployed we'll be brought to our contract dashboard here and next thing we need to do is set up our reward nfts so on the left hand navigation here we'll head over to the nfts tab and we're going to single upload here and the first one I'm going to do is the bronze reward so we'll set bronze reward here we then lazy mint you can add an image in description if you want to we're just adding a name for this and I'm going to Lazy mint this nft here we'll confirm that transaction I'll do single upload again this time for our silver reward and we'll lazy mint that as well confirm that transaction and then finally we'll do one last one for our gold reward and we're going to Lazy Min that confirm that final transaction there and there you go we now have our three rewards bronze silver and gold now you might notice on the left hand here we don't have a claim condition like we did with the ERC 721 and that's because each token in an ERC 115 five can have its own specific claim condition so we're going to have to set the claim condition for each one of these here and I'm going to specify this again as I did in the ERC 721 and erc2 Contra sections we are not going to be setting any restrictions to these claims we are making these claims open meaning that if anyone comes to these contracts they can claim these nfts directly from the contract so if you did want to restrict the claiming of these nfts strictly to the game you may want to use or Implement something like signature minting or third webs engine but what we're going to do here is just set open claim additions to each one of these nfts so I'm going to select the bronze nft first then we have the claim conditions tab we can add a phase and we can add public here we'll save that phase we'll confirm this transaction here once that is set we'll come back and we'll do the same thing for silver we'll hit claim condition add a phase public we'll save that phase to confirm that transaction we'll come back do our final reward which is the gold reward claim condition add phase public and save that phase we'll get our final transaction here to confirm and there you go we now have claim conditions set for each one of these nfts so bronze silver and gold code we have our ERC 1155 smart contract deployed and our nfts set that does it for this section in the following section we are going to then implement this into our unity game and again based on our player score they'll be able to claim one of these rewards and will display how much of each reward they have within the game as well so again you can head on over to the next section to start that if you need to rewatch any of the previous sections time stamps are all down in the description below hey everyone in this section we're going to be implementing the ERC 1155 smart contract we deployed in the last section into our unity game now again what we're going to be using this ERC 1155 smart contract for is achievement or reward nfts So based on a player's score by the end of the game if they scored less than 500 points they'll be able to claim a bronze reward they scored between 500 and 1,000 points they can claim a silver and if they score over a th000 they'll be able to claim a gold reward we're going to also display the amount of rewards the player has on the game as well and we'll combine the button and functionality to claim both the tokens and the reward in one click of a button that way they don't need to click two different buttons for two separate transactions we can put all of this and wrap it into one function so that being said let's jump on the computer here and let's Implement our ERC 1155 smart contract into our unity game so here again is the unity game rewards smart contract that we deployed in the last section we're going to take this contract address here we have our three nfts and again we set the claim conditions on each one of these so coming to my unity game here a Unity editor we're first going to add in the UI to our game and where this is going to be is in the game over screen so the same way we displayed our token balance we're going to display our reward balance as well so I'm going to turn off or disable uh the canvas main here I'm going to come over to Canvas game over and I'm going to turn that on so we have a balance here which is zero we're going to actually just take this balance title we're going to duplicate it I'm just going to bring it down going to come to scene here I'm going to bring this down below our panel here and I'm going to call this instead of balance I'm going to call it reward so let me just open up my inspector here uh we'll just call this reward so again I'm just taking that balance title changing the text to reward here and I'm actually going to take uh let's rename this to reward title and we're going to duplicate this let me just zoom out a bit and we're going to move this over to the left uh this is going to be called bronze here title and we're going to change this from reward here to bronze and we're going to just delete uh not delete duplicate that we'll name this one here silver and we'll delete uh duplicate it one more time and call this last one here gold so bronze title silver title gold title uh silver here we're going to change this to Silver and the gold we're going to change the text to Gold so now I can take the silver I can drag it on over right over here and then the gold one we're going to move it all the way over onto this side then what I'm going to do here is I'll take this balance amount I'm going to duplicate that one move that below our bronze Title Here this one's going to be called our bronze amount uh which we are going to move down and and this way here under bronze we're going to click on that duplicate that put it under a silver title this one is going to be our silver amount uh we'll move that over here and then finally we'll duplicate it one last time for our gold amount put that under gold title and we're going to just change this here to Gold amount and there we go we'll slide that on over under gold so we look at our game here when we get our game over screen now we should see reward and we should see a total for bronze silver and gold rewards and that's going to be our UI here for the game over screen now I'm going to change one last thing and it's going to be our in our panel here I'm going to get the claim button and I'm going to change the text of the claim button and the text is going to be claim tokens plus Rewards or Plus reward right because we're going to make sure that this button can both claim the tokens equivalent to the score plus claim the reward based on the user score so I'm going to just change the text there and then I'm going to come back up here I'm going to disable the uh game over panel here turn back on the canvas Main and let's now head on over into our script to be able to uh execute and claim the rewards of our nft so let's come on over here um back to our code editor here and what we're going to do first is we'll create that function uh to claim the nft so we're going to just come down all the way down to the bottom here I'm going to just create a public async void uh this is going to be called our claim reward now we do want to claim the reward and the one thing we need to know again is our player score cuz based on their score they're going to have to claim one of the three rewards so we're going to get a string here uh and the string is going to be our distance traveled right cuz we have that score saved in our variable uh that we set up here so what distance traveled uh what we're going to do is first get our contract here we're going to get our uh third web manager. instance. sdk. getet contract and we're going to provide it with our ERC 1155 contract address so we come back here copy that contract address come back to our code editor paste that in uh we now have our instance of our contract and depending again on the score we're going to claim one of three token IDs from our contract so we'll say if and we need to turn this uh distance traveled here into a uh integ so that we can compare it against something so we'll say int. parse and we are going to parse the distance traveled and if that is greater than or equal to 1,000 we're then going to await uh our contract and this is an ERC 1155 contract and we're going to call the claim 2 function and now with the claim two function uh we can take a look at the docs here for 1155 so we looked at 721 1155 if we go to claim condition claim 2 is going to take our wallet address as a string the token ID as a string and then the amount here as a as an integer so again recipient string token ID string quantity is an integer so over here at claim two the receiver of it is going to be our address the token ID that we're going to claim so if they score more than a th000 points they are going to get a gold reward nft now if I come back to my contract here the gold reward nft the token ID is token ID 2 so we're going to be claiming token ID 2 and we'll set the quantity here to one and that's if their score is greater than a th000 then we'll put else if their score is a score of distance traveled is greater than 500 but less than a th we're going to await the ERC 1155 claim to address is the same the only thing we're changing is the token ID that they're claiming which is token ID 1 which is our silver reward and then finally we'll say else they will await the ERC 1155 and then you get or actually let's put else if we can say they need to score a minimum of 100 points um or minimum of let's say 300 points cuz I think the first obstacle pops up around 200 so they need to score between 300 to 500 in order to get the bronze nft reward if they score anything less than 300 they don't get a reward they score 300 to 500 bronze 500 to 1,000 they get the silver anything over the th000 point mark they get to claim the gold so depending on the distance traveled score again we are going to call the proper claim to function uh with the proper token ID so that is going to be our function there now again remember we want to be able to claim the reward and the token all within one function so what we're going to do is create a new function here called public we'll say void and we're going to call this claim token and reward and what claim token and reward is going to do is it's going to call the claim token function and the claim reward function so the reward function here and our claim token function from earlier and it's going to do that all within one click of a button so what we're going to do here is we finished our two functions we're going to come back to our Unity editor here we'll let that compile and what I'm going to do here is in our game over canvas we're going to come over to the game over panel and we're going to come over to that claim button and all we're going to do is switch the onclick function from the claim token to claim token and reward now what this is going to do is again call both those functions and claim both our ERC 20 and the proper ERC 1155 token or nft for the user who played our game so with that said I'm going to play our game here and I'm going to a log in here so again we log in we passed the nft the ERC uh 721 check uh and then we start playing our game so let's just say right over there um we got 239 so actually let's start that cuz I'm not going to get an nft uh let's just score a little bit higher so let's go a little bit higher there we go we can uh hit the wall now so there you go I scored 401 so between 300 and 500 so when I claim this I should get a bronze reward so I'm going to claim tokens and reward here you can see it is claiming and we should be able to claim these tokens here we'll also be able to claim a bronze reward as well and you can see all our transactions here going through in our logs we actually check uh our ERC 1155 contract after cuz again we haven't read the data yet from our contracts but there you go our tokens were claimed uh our balance went up if I come over to our token contract here and we look at the supply of our rewards the bronze reward has a supply of one we just claimed a bronze reward and that does it for this section we created the functionality to be able to claim the proper reward based on a user score four we combined both the claim function of the tokens and the claim function of our ERC 1155 into one function in the next section we're going to similar to how we did the erc20 uh read information and data from the ERC 1155 contract and display it in our game over screen so we know how many how much of each reward the user has so join us over in the next section to learn how to do that hey everyone in this section we are going to be using our ERC 1155 smart contract from the past few sections in the last section we were able to specify which nft reward will be claimed on the user based on their score in this section we're going to read data from our ERC 1155 smart contract display it in our game so we can display how much of each reward the user has so let's jump on the computer here and let's get started so again this is a look at our Unity rewards smart contract uh we have bronze silver and gold we already showed that we can claim the proper reward and we claimed one bronze token here next we want to be able to display that information on our game so coming back to our Unity editor here let me stop Renning this uh we already have the UI set up uh let me just turn off canvas main here uh turn on the canvas game over so again we already set up the UI in the last section where we have the bronze silver and gold reward values down here here all we're going to be updating here is these values that are marked zero right here with the proper amount based on the wallet connected so we're just going to turn that back off turn on canvas main again and let's jump into our code editor into our blockchain manager script now we do need to create references to those three different text values so I'm going to come up here and we are going to create those three values here uh they're all going to be text M prugi so we have our bronze balance amount silver balance amount gold balance amount next I'm going to do is come all the way down to the bottom here we're going to create a new function here that is going to get us our balance so we're going to say public async uh void and we're going to call this uh get reward balance and for this we're going to get our contract so I can actually just come back up here copy this that's our ERC 1150 5 contract and then what we're going to do is set the balance for each one of these so what I'm going to do here is set the bronze balance uh this is going to await on our contract specify that it is an ERC 1155 and call the balance of uh when we're doing the balance of an ERC 1155 nft we need to provide the address that we're checking the balance for and then the token ID that we want to check the balance of so we take a look at our documentations for Unity here we'll do the 1155 and we're doing balance of again wallet address token ID what we get back in return is a string of the balance so now that we have the string all we need to do is set the bronze balance text amount. text equal to the bronze balance and then we'll do the same thing for silver and the same thing for gold so right over there we checked the about we get our contract we check the balance for bronze silver gold and we set the text to those balances now what we're going to do here is take our get reward balance and we want to make sure that we check that balance and set the balance again after we claim our rewards we also want to come up here to our invoke on logged in function here and we want to make sure that we check the balance of our rewards along with the token balance once a user logs in so with that said we can come back into our Unity editor here we'll let that compile we're going to open this up a bit we're going to go to the blockchain manager and we need to set the references for the bronze text silver and gold text so we'll come over to our canvas game over we'll come into the panel or we'll come in right over here we have our bronze amount so click and drag that in we have our silver amount and then we have our gold amount right over there so with those references Set uh we can now play our game here so let me just make this a little larger we'll run our game again we can sign in with Google we check to see if we own the nft uh which we do we can start playing our game so you can see we're playing here let's just uh let's let's go for a gold medal uh let's try score over a th here and again uh with this we'll be able to claim the specific nft or we should be given the nft according to our score so we should get get the proper achievement here I think there you go we scored over a th000 so when I claim the tokens and the reward you can see right here we did get the token balance I do have one bronze reward uh but when I do claim the tokens and reward here I should get a th000 more tokens and I should also see my gold reward value go up as well so let's hit claim here we're claiming our uh tokens and reward you can see our eth transactions are going through down here at the bottom so we'll do that we'll also get our transaction hashes there as well and we should see that our tokens have been claimed you can see gold uh updated here to one and our balance increased by 1,043 so there you have it we now are able to interact with different types of smart contracts within our game we did erc20 tokens which we can claim the amount of tokens equivalent to the score that we get we also did ERC 721 tokens we use that as an nft pass again you need that ERC 721 in order to get access to our game once your wallet is connected and then finally we created ERC 1155 reward nfts So based on our score we can get different achievements or reward nfts and again we WRA that all into one button here so we can claim that token and reward and the balances will update for us the last and final section of smart contracts is is deploying our very own custom Smart contract and being able to interact with that within our game the custom Smart contract that we're going to be deploying is a leaderboard like contract where a player will be able to submit their score into our leaderboard and they'll be able to see where they rank within that leaderboard as well so again you can not only use pre-built smart contracts or standardized smart contracts like ERC 20 721 and 1155 but also create your own smart contract and get creative on how you can Implement them into your Unity games so join us for that in the next section if you need to go back and rewatch any of the sections again just a friendly reminder that all the time stamps are down in the description below but head on over to the next section and let's build ourselves our very own leaderboard smart contract hey everyone in this section we're going to continue interacting with smart contracts with our unity game now in the previous sections we covered interacting with standardized contracts like erc20 ERC 721 and ERC 1155 smart contracts in this section we're going to be learning how to interact with our very own custom Smart contracts in our web 3 game and in this specific section we're going to create our very own leaderboard contract which is going to keep track of the scores in our game so we'll map our users wallet address to their score and we'll be able to display them their ranking amongst other players so again in this section we're going to work specific specifically on creating the smart contract and then in the following section we'll show you how you can interact with these custom Smart contracts that you build for your game so on my computer here I have my terminal open and we're actually going to use third web to create and deploy our very own custom Smart contract I'm going to run mpx3d web create contract here and this is going to allow us to create our very own contract and deploy it utilizing third web's dashboard so I'm going to uh create my project name here I'll call this Unity uh leaderboard now you can choose the framework you want to use for deploying your contract you can use hard hat or Forge I'm just going to use hard hat here for this example then we're going to name our contract so in this case I'm going to name it the leaderboard contract and we can select the contract we want to start from now we can choose uh again standardized contracts like 72120 or 1155 live and we can then customize and add our own functionality to it uh we're not going to do that here we're just going to start from a completely empty contract here and write our own leaderboard smart contract out and once that's done we'll change into our Unity leaderboard here and open this up in our code editor and once we have that open in our code editor we can start creating our contract now in this contracts folder uh if you're using hard hat if you're using Forge it'll be under your Source folder folder but within that folder you'll have your contract. and you should see an empty solidity file here that we can start to edit now I'm not going to go over all the basics and everything of solidity and creating smart contracts in this video I will however walk through a high level of what we're going to be creating as we create the smart contract and this is going to be a very simple smart contract that we build so if you're not familiar with solidity or maybe you're new to solidity you'll still be able to follow along through this but right over here we have our solidity contract file you can see we declare what uh version or what compiler of solidity we're going to be using we set our contract here which I'm actually going to call our leaderboard contract uh we have our Constructor function which we're not going to be using within uh this solidity file here the first thing I'm going to do is create a mapping and this mapping is going to be from our address to a uent uh we'll say 256 and this is going to be a public variable called uh scores so what a mapping is going to allow us to do is take a address and map it to a value so a key and a value so an address to a value here which is going to be a un 256 and in this case this is going to be the player's score so whenever a player submits their score we'll take their wallet address and we'll update their score right over here now this is going to be stored in a scores variable which is going to be public so anyone who has access to the smart contract can view this we're also going to create a another variable here it is going to be an array of addresses uh which is going to be private we're only going to use it within this smart contract here and we're going to name this variable players So within this smart contract we're going to create a array of addresses private means we're setting it only to use within the smart contract and we're naming that again that variable players then we're going to create an event this event will get emitted to the blockchain and we can actually view these events on the contract itself uh so we're going to call this a score added so whenever a score is added uh we'll call this event right over here which is going to have an address uh which will say index the player so we'll show the address of the player who submitted a score and then we'll also add the information of their actual score which is going to be a u 256 and every time we want to emit this event here uh we can call the score added and again that event will be added onto the blockchain so we're going to create a few functions here that we're going to use uh the first function is going to be for adding a score or submitting a score so we'll say uh submit score and when we submit a score we need to know the score that we are submitting so we're going to say U into 256 uh which is going to be the score and this is going to be for external use so we're going to be able to call this function externally here so say external so first thing we're going to do is we're going to check if our scores and we're going to provide it with the sender of this transaction so whoever's sending a transaction we're going to get their wallet address we're going to check their wallet address and we're going to check what value or score they have mapped to their wallet address now if their score is less than the new score that they have then we're going to want to update that score if it is less then we don't want to update their score because then they'll be ranked lower than what they are so we only want to be able to increase and submit their Rank and score if their new score is higher so what we'll do here is we'll set the new scores of the message sender to the new score that they have have when we do that we will then emit the score added event here and we will give it the address of the player which is going to be the message sender and their new score which is going to be the score that we provide to this function so that will be our function for submit score next function we're going to create to see is if a player is registered and by registered it means are they added into our array of addresses uh that we named players here and this is how we keep track of of who our current players are and where they're going to be ranked within those players so we're going to create a function here called is player registered and this is going to take an address of the player and this is only going to be an intern this is only going to uh be a function that we run within this contract so we're going to make it a private function it is only going to be a view function here uh and it's going to return a bull so going to return if they are registered or not then we'll create a for Loop here which is going to check the uh uent we'll say I equal Z and as long as I is less than the players do length and we'll increment I and what we're going to check is if the uh players at that index is equal to player then we will return true so this is how we're going to check if they are registered within our array of addresses and if not then we return false so what we can do here is also when we submit a score is if this is the users's first time or player's first time submitting a score we want to be able to register them as well so we'll check if the score here is greater than zero and the player is not registered right so we provide the is player registered with the address of the uh player which is the sender and if they are part of it then we don't do anything here but if they aren't registered then we are going to add them to the array of addresses here so we're going to get our players. push and push the new address of the message sender here and then finally we're going to create a one more function here to get the rank of the current players so we're going to say get Rank and get rank is going to take the address of the player here this is going to be an external function that we can view and returns us a rank which is going to be a u 256 uh that un 256 is going to be our rank so in order to check the rank here what we're going to do is get the player score uh we're going to just create a uh variable here called score and this is going to equal the underscore scores of the player depending on the address that is provided and if score uh is equal to zero then we're going to return zero then we're going to create a variable called uh 256 then we're going to create a variable which is going to be a un 256 called highest score highest scores which is going to equal zero then we'll create a for Loop which is going going to take the addresses from our array of addresses and check their score to see where we rank amongst them so if we're going to get the uh index which is going to start at zero get the score of that player and if that is higher than our current score that we provided then we are going to set the highest score and increment it up and we're going to go through those top scores and see where we are placed within them so finally here once we get our index in which we stand we're going to return the highest score plus one uh because we'll be ranked one more than whatever index we land on and that's going to give us our ranking amongst the addresses within the array so there you go that is going to be our very basic leaderboard contract again we just have an array of addresses here that we are using to get the rank of our current score or our current address we have a mapping of addresses to their scores we have an event that's emitted here and we have functions to submit our score check if a player is registered within our array and to get the ranking of that address so now that we have our contract complete let's deploy this so I'm just going to open up my terminal here within my code editor and I'm going to run mpx3 web deploy this is going to detect our project type compile our project and this will open up a tab in our browser here and this tab will allow us to then deploy this contract using third web's dashboard so you can see here we have our leaderboard contract all I need to do is select the network or chain I want to deploy this contract to and in this case like all my other contracts I've deployed it to Mumbai here so I'm just going to hit deploy now we'll get a transaction here that appears we'll hit confirm we'll get one more popup here for a signature request to add this contract to our third web dashboard so we sign that and there you are we have our leaderboard contract now deployed we can see here we have our contract address deployed on Mumbai if I come to the Explorer tab on the left we have our submit score function and we have the read functions of getting our rank as well as seeing our score mapping of our address to their score and that was a quick deployment of a custom Smart contract that we're going to be using within our game game for this course now what we're going to do in the next section is implement this smart contract and we're going to start interacting with it and be able to execute the functions from our contract within our unity game again if you need to jump around or rewatch any of these sections all the time stamps are down in the description below but head on over to the next section and let's get started on implementing this into our web 3 unity game hey everyone in this section we're going to be continuing off with the contract that we deployed in the last section which was our Custom Contract which is a leaderboard contract so if you haven't deployed that contract or you want to rewatch that section head on back to that section there but in this section we're going to be taking that contract and implementing it into our Unity Web 3 game and we're going to be able to interact pull the information from that contract what Global ranking our player is depending on their wallet address and how can they be able to submit their score when they score a new high score so without wasting any time let's jump on the computer here and let's get to implementing it so right over here this is a look at the leaderboard contract that we just deployed and what we're going to do first is head on over to our Unity editor and we're going to set up some of the UI components here now if you are using the endless Runner example game that we provided at the beginning of this course and that we've been working with since the beginning of this course we do have some UI components already that you can use so you can follow along with this tutorial here so over here I'm going to come over to my canvas Main and I'm going to disable that and I'm going to come over to the canvas game over and enable that one there now within that game over uh canvas there is the game over panel and within that you'll have uh a text rank so you can enable that that will show the global ranking of the player here and we have a submit Button as well where the user can then submit their score we can check their ranking and then update their ranking right here and of course we still have our claim rewards button button our restart button so the claim rewards button is going to claim again the total distance traveled plus depending on the player score a bronze silver or gold reward and we have all that information displayed down here as well so that's going to be the UI components we're going to be using is This Global ranking where we'll be able to get the global rank or the ranking of the player from our smart contract and display it here as well as submitting their new score and getting their new ranking so that's the uis that we're going to be using from Unity here now let's actually Implement how we're going to be able to interact with a custom Smart contract and to do that we're first going to head on back to third web's documentations here we're in the unity docs I'm going to go to contract interaction and I'm going to head over to get Contract first so in here you can see that we can use the SDK and get contract and just provide the contract address as we've been doing with as we've been doing with our pre-built contract like erc20 721 and 1155 now because we are going to be interacting with a our own custom Smart contract we're going to provide a second parameter here for get Contract which is going to be my ABI so we're going to actually provide it with the ABI now the ABI must be in a c escaped string uh preferably without spaces or line breaks for the best experience here so we're going to give it the contract address plus the G Shar escaped string here of the ABI now to get the ABI you're going to just come to your contract Here Come To Source you have the ABI here that you can copy and I just used chat GPT to convert this for me so you can just say hey chat GPT convert this to a c Escape string provide it your ABI and you can get your C string right over here uh that you're going to use and provide as that ABI parameter in the get contract so with that said now we can come back to our Unity editor here let's go to our blockchain manager let's open this up and edit this script so what we'll first do is create a function to get the rank of our current ranking of the user that is logged in so we're going to make internal async uh this is going to be a task which is going to provide us an integer and this task is going to be called get rank so in here we're going to create a variable for our contract this is going to use the third web manager here we're going to get an instance sdk. get Contract right now in here again we're going to provide it with the contract address and then we're going to provide it with our C escaped string of our ABI so let's come back to here let's get our contract address here let's paste that in right here and then let's let's get that string that we're going to provide for our ABI so I just come back to chat jbt copy that right over there and paste that in so there you go now we have our contract let's then uh get our rank so we're going to save our Rank and then we are going to call the get rank function from our contract now coming back to the documentations here how do we read a function right so we can read a function by using contract. read uh and then we can provide the function name and any arguments that the uh function needs um or requires so in this one here if we take a look at our explore on our contract and we go to read the get rank function needs the address of the player so coming back to our script here rank here we're going to await contract and then we're going to say read which is going to give us an INT here and we're going to call the get rank function and provide it the address variable here which is going to be the address of the the player and then at the end here we're just going to return the rank here and that should give us back the rank of where the player stands next we need to also create a function that is going to submit the new score of our player so same thing here we're going to create an internal async task here uh this one's going to be called uh submit score and this is going to take a float uh which is going to be the distance traveled and in here same thing we're going to get our contract so we'll just copy this right over here and then we are going to await our contract and if we take a look back at our documentations let's see how we can write to our contract so same thing we can contract right function name and then we can provide it with the arguments and everything that are required for our function so if we take a look at our contract here write submit score we need to provide it with the score so contract. write and it is going to be submit score and then we need to provide it an integer of our distance traveled so we're going to provide it with the distance traveled which is going to be our player score and we'll change that into in and provided there and that is going to execute and submit the score and then we will get back the ranking of our player so again these are internal task here we're actually going to come back to our Unity editor let that compile real quick then we're going to come to our UI manager open and edit this script here and if we scroll down you're going to see right over here we have a private void we have a function a private function right over here called show game over panel this show game over panel happens when our player um ends the game right they hit an obstacle there's a listener here that is then going to toggle the show game over async panel and what we toggle that we're going to want to get the rank here so we're going to get the rank uh which is going to await our blockchain manager script uh get an instance of it and then we're going to call the get rank function we're going to start that in a rank variable then we are going to change the rank text to the global Rank and the rank right over here so that's how we're going to update the ranking and then we have a function here called submit score which again we are going to await the blockchain manager script here we're going to get an instance of the submit score we're going to provide it with the character manager instance and distance traveled so the distance traveled that the character went that's going to be the score that we submit we'll then check the ranking again using get Rank and then we will update the ranking text to the new rank based on their new score so now with that when we come back to our Unity editor here we'll make sure everything is correct by coming to our submit button make sure that we have the onclick here for submit score and then we have our text rank right here submit score and once that's done we can then test out our game here so let's uh actually disable canvas game over and enable canvas main here and then we'll run this game we will sign in there we go we're playing our game so let's play this game here and there we go so we don't have a current ranking uh a distance traveled here is 237 we can submit our score so you can see it's loading our Global ranking here um it's executing that transaction using our custom Smart contract it's getting our ranking um and you can see down here our transaction is going through once it's done it should rank us at number one because we haven't uh we don't have any other players ranked in here with us we should also still be able to claim our tokens and rewards and restart our game here so there you go we can restart our game and we can continue playing let's try a different account here so we sign in with a different Google account here we're actually going to get prompted here uh saying that we don't own a pass cuz again this is a new uh account here so we again we have uh our game token gated to an ERC 721 we know that this here works so let's claim the pass uh so we can claim the pass here okay so we're claiming our pass once we've claimed the pass it should allow us to start playing the game and and we'll try and get a very low score to see if our ranking here works so there you go we claim the pass we should start playing our game now let's come right over here so we scored at 245 now I don't remember if that was higher or not but we'll submit our score here you can see our transaction is going through with our custom Smart contract here checking our Global ranking and we should then receive our ranking right over here okay so it was higher than our previous one so we're now ranked number one you can see here we can still claim our tokens and rewards so we can claim that we should be able to claim our 245 tokens we should be able to get our reward actually I don't believe we are going to get a reward because I think 300 was the minimum we set to get a bronze there you go tokens claimed yeah we got 245 we didn't get any rewards here and then we can restart okay let's end this let's uh go back in here let's sign back in with our previous account so we signed back in with our previous account here so let's take a look here let's play the game let's you know let's score a little bit higher this time there we go so you can see right here my Global ranking updated to two because we scored higher in our previous account uh we scored 446 this time so if I submit our score here it should update our Global ranking to rank number one there you go and now our new Global ranking is set at number one we can claim our tokens and our reward uh we should claim the 446 tokens plus a bronze reward because we did score above 300 and less than 500 here so once those transactions go through we should see that our tokens have been claimed so we claimed our tokens and that should update to two and then our balance here updated by the 440 six so there you have it we implemented our very own custom Smart contract into our unity game you can see how easy it is to even Implement and create your own smart contracts and still use them read data from them execute functions all within Unity so you can get really creative create your own smart contracts that have your own gaming functionality and everything and Implement them into your Unity Web 3 games and that covers all the different types of smart contracts that you can Implement into your Unity games from standardized contracts erc2 ERC 721 and ERC 1155 smart contracts to again your own custom Smart contracts in the next section we're going to cover something called erc20 pay masters which is a really cool feature that you can Implement into your web 3 games to really enhance the experience for your players so again head on over to the next section if you want to learn more about erc20 pay masters check out the time stamps all down in the description if you need to go back and rewatch any of the sections that we have already covered hey everyone in this section I want to cover something called erc20 pay masters now as of recording this course we don't have our erc20 pay masters released just yet but it is coming very soon and if we do check down in the description below and you do see that we do have a link to another video that means we do have our erc20 pay masters ready you can click that link watch the tutorial and see how you can implement this amazing feature into your web 3 unity game but what I did want to do in this section is go over the concept of what an erc20 paymaster is and why it could be a key component to enhancing your web 3 game so if you're not too familiar with what a pay Master is it's something that comes with account abstraction or ERC 4337 now if you do want to go into more detail uh we do have a course going over what account abstraction is going over how it works in detail and you can learn a lot more about account abstraction through that course in this section I'm going to do a quick overview of how account abstraction transactions work where a pay Master comes in and why something like an erc20 pay Master is revolutionary to web 3 gaming so when using account abstraction what you're going to be doing is you're going to have a bunch of user operations which gets added to a user operations M Poole from there they get pulled into a bundler and that bundler will then bundle those transactions up through the bundle transactions it is then submitted to an entry point contract now this entrypoint contract is a contract that exists on every single chain or network and this is what's used within ERC 4337 now within that entrypoint contract the user operation gets validated and one of the validating checks it does is to see if the gas for the transaction is covered now normally a user executing the transaction has to be the to provide the tokens to pay for the gas but with account abstraction and with ERC 4337 you can introduce something called a pay master and a pay Master can be set up where that pay Master will hold the funds and will then pay the gas on behalf of the user so in this case you could set up a pay master that takes care and sponsors all the gas for your players you can configure this for it to sponsor only certain transactions Maybe the amount that it can sponsor you can have all that configurations within using account abstraction so where erc20 pay Master comes in is you can now create your very own pay master and you can configure the ways in which the gas is covered or sponsored for your players now the two different types of erc20 pay masters will be introducing is a fixed erc20 pay master and a dynamic erc20 pay master and what these pay masters are going to allow you to do is configure how your players pay for gas for example a player could pay gas with a game token or they can pay their gas with maybe something like usdc so if we look at a fixed erc20 pay Master what this is going to allow you to do is use a fixed rate of a token to cover the gas so in example would be maybe you have a game token that you use within your game you allow your player to purchase these tokens but every time they execute a specific transaction it costs them a specific amount of tokens so we'll keep the example very simple here maybe for every transaction that you want a player to be able to execute on chain it costs them one game token so no matter the cost of gas which is used to execute the transaction on chain a player will always pay one game token in order to execute it so for a player all they see is the payment of one game token in order to execute transactions on the backend side you're taking the one game token and then you are executing the transaction no matter the cost of gas for game developers this can help you offset covering gas for players because you can then charge for the game tokens and use those funds to then fund the actual pay master that will be actually executing the transactions and covering the gas so again fixed rate is an example of a player only need needing to provide one game token or a fixed amount of game tokens to execute transactions on chain now the dynamic erc20 pay Master is slightly different and for an example of a dynamic erc20 pay Master we'll be using usdc here so instead of charging the player a native token let's see we're on eth mainnet so instead of charging the player eth for gas we can charge them the equivalent value of usdc so what this dynamic erc20 pay Master does is we'll use onchain oracles to get the market value equivalent of the token that you want a user to spend to the actual native token that needs to be spent to cover gas so in this example here maybe you execute a transaction and gas is going to cost you .1 eth and let's just say that's equivalent to 20 usdc so what a player will see is that they will be charged 20 usdc in in order to execute a transaction now behind the scenes again we'll be using onchain oracles to find the market value equivalent and then executing that swap on runtime of a player executing the transaction now the example I provided was with usdc but you can do this with any token keeping aware that you would need liquidity available through something like Unis swap in order to execute this so it can't be done with every token but you could use popular tokens out there in exchange of using the native token in order to pay for gas and just like a fixed erc20 pay Master the dynamic erc20 pay master has its advantages where you can utilize other popular tokens instead of the Native token in order to cover gas for your players it gives the ability for your players to use other popular tokens instead of just the native token of the chain you are deployed on and those are the two erc20 pay masters you can look forward to again check the link down in the description below if we updated that link you can check out that tutorial on how to implement it into your game we did want to include it in this course though because it is something very powerful that you can introduce imagine having a game and a game token and a player never needs to touch external cryptocurrencies everything is within that game token but with the blockchain you'll also be able to then use that token say in another game so maybe game one has a game token and game two also utilizes that same game token you could use that game token in that game as well like we mentioned with Dynamic erc20 pay masters you can also utilize pop other popular tokens that people may have within your game so you can now create this ecosystem of web 3 games utilizing a single game token or utilizing popular tokens and you can use and create an ecosystem where you can earn tokens in one game and spend them in another and that's an eyeopener and a different way of looking at gaming but it's something that web 3 and blockchain Technology introduces so again I hope this section opened your eyes to the possibilities and the potential of web 3 gaming again keep an eye out for that erc20 pay Master tutorial we'll link that down in the description below but that does it for this section and we've actually completed building our game join us in the last few sections where we'll go over how to build and deploy these games for things like web native platforms and mobile devices hey everyone and welcome to the final section of this course and in this final section we're going to be building and running our game that we just built within this course now if you've been following along with the example that we provided in the beginning of this course it was a endless Runner game and we implemented a lot of different web 3 components to our game from being able to sign in with a social login which then generated a smart contract wallet for the user we token gated our game to an ERC 721 nft pass and based on how well our player did in the game they are able to collect erc20 tokens equivalent to their score and based on their score they could also claim certain rewards we also created our very own custom leaderboard contract and players can then submit their score and see how well they rank against other players and now that our game is is complete we can now build and publish our game so in this section we're going to cover two different builds we're going to be doing our webg build which is going to allow your game to run on a browser we'll also do a native build and build a native application for your desktop we do also have mobile builds but we're not going to cover that in this video although we do have documentation and guides for if you are a mobile game developer you'll be able to easily follow those guides in the documentation and deploy your web through fre game on mobile devices but again for this section we'll be doing web goo and browser and Native applications so let's jump on the computer here and let's Deploy on webgl first again we have our game here and we can just run through it really quick just to make sure everything is working anything that you play through this editor here is pretty much how the game will be when you build and run this game so let's play this here and let's just make this a little bit bigger you have our social logins here so we'll sign in with Google you can see here we are connecting to our account we're connected our score is going we can now play the game here so as we play this game let's just score right here there you go we scored 599 you can see our Global ranking here is one I'm not going to submit a score here but I will claim and re our rewards and tokens so again we should get 599 tokens we should also claim a reward I believe we'll get a silver reward here so you can see all our transactions are going through once our transactions have been processed on chain there we go claim tokens are claimed we got a silver reward our balance has updated we can now restart and start playing our game over again so we know our game works we're going to stop that right there now I'm going to come up to file I'm going to come to the build settings and in our build settings here again we're going to do webgl first so on the platforms here I'm going to select webgl I'm going to select switch platforms really quick and there you go we switched over to webgl now I'm going to come over to I'm going to come over to the unity SDK and GitHub here and if we scroll down you can read a lot about the unity STK but you can also read some things about the build here in our build if you look here in webgl um in order to communicate with the ska in webgl we need to build and run our project uh one thing we need to do is open our build settings and select webgl as a Target platform that's something we already did already uh we need to open our player settings and make sure that the resolution and presentation is uh under third web so we'll do that right now let's change on over here open our player settings right here and under resolution and presentation hit that drop down we're going to want to make sure that our webg template is we'll save and there you go once it builds and runs the game it should open up in your browser so let me just refresh this real quick you can see our unity game loads and you're brought to our login screen just like you were playing with it in the editor now again because we used embedded wallets here uh when we try to attempt to log in and we select our email uh you're going to get stuck on this screen or this loading spinner here and again that is recorded in our documentations so this is something that we're going to have to work around uh and we can do that right over here so we're going to come back to the documentations and you can see what we have to do is we have to host the build or we have to run it locally after adding the cross origin opener policy header and setting it to the same origin allow popups so right here is what we can set up all we need to do is is add this into a server file so we can run it locally with the cross Origins opener policy so I'm going to open up my terminal here and we're going to change directory into our um project here so mine is the endless Runner example uh YouTube vid and in here we're going to then change into our folder that we created for when we built and run our webg so mine was webg and in here I'm just going to open this up in the my code editor so in here I'm just going to in that webgl folder create a new file we're going to call this our server.js then I'm going to open my terminal in my code editor here and I'm going to run mpm init Dy this is going to create me a package.json file then I'm going to run mpm install Express and I'm going to come back to the document ations here copy this code snippet paste that into my server.js file and then I'm going to run node and then my server.js file here and this will run on my Local Host 8000 from here we'll log into our unity game you can see our unity game is up and running locally here within our browser again we can select Google select our email to sign in with and there you go you can see we don't get stuck on the spinner page anymore our game starts to play and we can now play our game and we're again playing it in our web browser so if we were to publish and Host this game ourselves this is what it would look like for people who come to our web page and start playing so there you go you can see uh rank number one my score is 751 I have uh I can submit my score here it's submitting my Global rank here it's going to pull back my rank uh based on my new score I can also claim my tokens and rewards as well so we'll do that once we get back our Global rank here there you go still ranked number one I can claim my tokens and rewards so I'm going to claim the 751 tokens here uh I'm going to also claim another silver reward here and once this claims there you go claimed tokens uh my balance increases here I get a silver reward I can restart and then I can log in and start playing again so that was an example of our webg build again if you are using embedded wallets you do just have to follow this documentation here create that server.js file and then just run it so again that was for webgl now what if we wanted to do this for a native desktop app here uh we can come back to our Unity editor here I'm going to switch this back to Windows Mac Linux so I'm going to switch platform and once you have your platform and architecture set we're going to come into player settings as well and make sure our resolution and presentation here are full screen mode we're going to select windowed here and I'm just going to select so I'm just going to make sure that my um game comes out a bit smaller so I can fit it in my screen recording here uh you don't have to do this you can do full screen if you want to uh I'm just going to close that and then I'm going to build and run we're going to save this under uh Mac here this build under Mac and hit save and there you go so this is running natively on my desktop here this is the application that was built we're running it here we can sign in with Google you can see here it's going to open a web page for me to sign in I select my email I can then close this tab head back on over to my game it's going to log me in and we should see our distance counter start to increase there we go and now we can start playing our game so let's try go for over a th000 in this one uh we'll just let it run for a little bit so as we play our game our score is increasing again I'm signed in with an embedded wallet connected to a Smart wallet and let's see we're almost there and let's go ahead end this game you can see I scored 11,0 and4 we can claim our tokens and everything natively here this app is running on my desktop so I should collect a gold reward as well as claim 1100 tokens so we'll let that go through you can see here still claiming there you go tokens have been claimed that increased here balance has increased and our game is now successfully running as a native application on our desktop and there you have it we built our game we ran our game both on browser and natively as an application on our desktop again you can follow the documentations and everything all of that will be linked down in the description below and you can not only start building but publishing your games for people to start playing so that was it in this section and that is actually the end of our course we covered a lot of things in this web 3 gaming course from what is web 3 gaming and what new features and potentials it brings to gaming we covered a lot of how you can Implement web 3 into your Unity Web 3 games from connecting wallets this includes connecting web 3 wallets like metamask coinbase or wallet connect wallets to even utilizing things like inapp wallets or embedded wallets to allow users to sign in with social logins or with email along with account abstraction and how those features of account abstraction or ERC 4337 can really enhance the user experience within your web 3 game we also covered how to interact with smart contracts this includes standardized contracts like erc20 ERC 721 and ERC 1155 we use the erc20 contracts as a in-game token that we can earn within our game we used the ERC 721 within our course as a pass that token gated the game and only users who owned the pass were able to play and then we used erc1 55s as nft Rewards or achievements within our game not only can you interact with standardized contracts but you can also interact with your very owned custom Smart contracts that you choose to create and deploy with that we were able to create a leaderboard contract and we can now see where our players rank within our game and that is and that data is all stored on chain we also covered a little bit about what erc20 pay masters are and how that can revolutionize the way players play with your game and the ecosystem in which you can create tokens and again keep your eye out for a potential video on how to implement that into your web 3 games we'll keep the description updated with that link down in the description below and then finally we learned how to publish and build and run our games on web browsers along with natively on our desktop so again I hope you folks enjoyed this course I hope you will learn a lot from it and I'm excited to see what games are going to be built utilizing third web's Unity SDK again web 3 gaming is going to change and revolutionize the way we play our games and how we interact with them and third web's Unity SD is bringing the ability to easily build and integrate web 3 functionality into those games so again if you're folks did enjoy this video don't forget to give it a thumbs up hit that subscribe button don't forget to turn on the notification Bell so you don't miss out on other tutorial videos and other future courses as well if you folks need any help or any guidance we'll drop a link down in the description below to our support Channel where we can open up a support ticket and our support team will be happy to help you out and answer any of your questions but again I hope you folks enjoyed this web 3 gaming course can't wait to see what web 3 games you build and until next time see you for
Info
Channel: thirdweb
Views: 2,951
Rating: undefined out of 5
Keywords: nft, play to earn, web3 gaming, blockchain gaming, unity tutorial, unity, unity programming tutorial, unity tips, unity course, unity course for beginners, game development unity, learn programming, unity complete course
Id: Xekm67cHsVM
Channel Id: undefined
Length: 181min 32sec (10892 seconds)
Published: Fri Mar 29 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.