This tutorial demonstrates how to connect a wallet to the Web3.unity SDK in Unity, covering UI setup with the Connect to Wallet prefab, understanding connection providers (WalletConnect for editor/mobile/WebGL and MetaMask for WebGL), handling lightweight vs full Web3 instances, and executing ERC20 token transfers using async/await patterns.
Connecting a Wallet to Web3.unity: A Step-by-Step Guide
Added:hey everyone and welcome back in this video I'll be showing you how you can connect a wallet to the web 3un SDK so that you and your users can write to the blockchain okay we're now back inside of unity and the web3 unity test class that we have created in the last video is now empty to Showcase how easy it is to connect your wallet first we need to create a UI canvas let's set the UI scale mode to scale with screen size let's set it to the full HD and in inside of that canvas let's just add a prefab called connect to wallet make sure that in the search you select either in packages or all the connect to wallet is a nice script that automates the process of connecting to the wallet for you it also has this remember me toggle that indicates will the session be stored so that it can be restored once you reenter the play mode or once you reenter the game Let's click on web3 unity and in here we have connection providers that we have populated in the previous video so we have the wallet connect and metamask let's click on play and see what's happening so if I click on connect I will only have wallet connect as my connection provider and that is simply because metamask is only used in the actual webgl builds while wallet connect is used in editor mobile and webgl let me quickly connect my metamask wallet from my phone to the wallet connect okay I have connected my metamask wallet wallet from my mobile phone to the wallet connect and in here you can see that this is my public address I can copy it over so that I can send it to someone or whatever you want to do with it I can also log out I'm not going to log out just yet because I want to show you that now because in the connect wallet we have this remember me toggled on we can come back to the play mode and after a couple of seconds our connection to the wallet connect will be restored in the future versions of our SDK the remember me will also be part of the UI but of course by all means means you can Implement that remember me feature inside of the UI yourself now let's exit the play mode Let's go into the web 3 Unity test and inside of the web3 unity test let's add the start method and inside of it let's subscribe to web3 unity. web3 initialized event and let's also in N destroy unsubscribe now this object is a topple so it has the web three instance but it also has has the bull parameter that indicates if the web3 instance that has been initialized is lightweight the lightweight instance in our context means that web 3 instance that is passed as the first argument doesn't have bound the wallet itself but it can only read from the blockchain so let's debug.log obj do is lightweight go back into unity and see the results and there it is now it says false because we have the wallet connected but if I log out we will immediately initialize the lightweight version so the output here will say true now let's reconnect the wallet and we're logged back in let's just exit the play mode get back into our IDE for now I will create a private bull here and we'll call it is full web3 initialized I will also add a serialized field again called contract address address as well as transfer ERC address because I want to utilize the transfer function from the erc20 actually now that I think about it I don't need this I just need to check here if obj that is lightweight equals to false if it does let's transfer some erc20 so let's type in OB j.
web3 erc20 transfer the contract address is the contract address the destination address is the transfer erc20 address and the amount is big integer. p 10 to the power of 10 the amount is always in way so I'm using big integer here now let's get back into Unity test this out I have populated these contract addresses and transfery address I'm now back in my metamask on my mobile device and I am getting the prompt so let me confirm it so the transaction has been sent but I didn't get any sort of notification in the debug log that the transfer has been completed so let's fix that to fix this we need to make this method async and we need to await the transfer method call so let's call it transfer because this transfer doesn't basically return anything here it says object but in reality it doesn't have any return value we can simply just call here debug.log transfer happened so that we can indicate when the transfer happened in the future lessons we get introduced to blockchain events so that we can actually get notified when the transfer happened and we can also get all the details about the transfer now let's go back into unity and test this out again so I have confirmed the transaction on my mobile phone and as you can see we get the log the transfer happened and that means that our transaction has been successfully executed on the blockchain if the transaction was not successfully executed we would get some sort of an exception here but luckily for us everything went smoothly now in the next lesson I will be adding additional login provider web3 o so that I can show you how easy it is to add a new login provider and I think that web3 o is super useful because it also allows your users to use social logins so that they don't have to be crypto Savvy or even have any wallet themselves so I'll see you in the next video
Up Next

Deploy Smart Contracts to Ethereum Using Nethereum Tutorial
@JuanFranBlanco
27.8K views•2016-08-23

IFS Therapy Demonstration: Complete Session with Unburdening
@IFSCA
95.9K views•2021-01-13

FastAPI vs Flask vs Django: Choosing the Right Python Web Framework
@TechWithTim
302.5K views•2024-05-26

Game of Thrones Opening Credits: A Cinematic Analysis
@gameofthrones
46.3M views•2011-04-18
Related Study Plans & Knowledge Roadmaps
Structured learning paths in General & Interdisciplinary Studies







































