In your index.tsx file we will import the useEthereum hook to help us with all things related to the wallet connection. (You can also import from other chains we support using useMetis or useFlow.)
All we are doing is simply destructuring (syntax for fewer lines of code) these properties from the useEthereum hook to give us access to use them where we like.
address - gives us access to the user’s wallet address if they are connected
disconnect - function that is called to disconnect the user from the Dapp
connect - function that is called to pop up the wallet choices and then ask the user to connect to the Dapp
Here we are using HTML to build a button that says “Connect Wallet” when we do not have a wallet address and otherwise shows the wallet address if it does exist.
When the user clicks on the “Connect Wallet” button, we simply call the connect function which automatically leads to a pop up for the user to choose which Wallet Provider they are using and proceeds to ask the user to connect to the Dapp from their wallet.
When the user is connected and clicks on the same button, the disconnect function is called which automatically disconnects the user from the Dapp.
Step 5: Run yarn dev to see it in action!
Note: Make sure you are on the Rinkeby Test Network for it to work
The end result code should look something like this:
Congratulations! You have officially made your first step in creating a Dapp!
Next steps: Here is a GitHub repo that follows these steps and is already hooked up to the Hyperverse with a beautiful UI for you to fork and start building right away!
Browse more from our latest stories and announcements!