📂Add wallet connection to your react app
This a quick guide walking you through how to manage wallet connection using Mintbase-js. We currently support a stable version only on Next.js, soon we plan to give support to more libraries and frameworks. We strong recommend that you use the first method and build on top of our examples repo. Also recommend the read of @mintbase-js/react documentation
First Method: Clone the starter template
You can easily test Mintbase Wallet, using our Simple Login example with Next.js 14 on this repository:
https://github.com/Mintbase/templates/tree/main/starter-next , just do a pnpm install
on the next-js folder and pnpm run dev
any issues or troubleshooting help you can send us a message on our Telegram Channel
or you can also run on the terminal the command npx create-mintbase starter-next
and it will automatically clone the starter-next template
Second Method: Install yourself
Step 1: Install
Install the mintbase-js react package
npm install @mintbase-js/react
or
yarn install @mintbase-js/react
Step 2: Add Mintbase Wallet Context Provider
Add the WalletContextProvider
to the root entry point of your app.
The below example shows how to do this on a Next.js app but the idea is the same. For React the equivalent should be done in the index.js file.
Step 3: Create a Wallet Connection Component
Import use wallet and use it to get the necessary functions.
Use the connect method to provide the wallet selector UI where you can select which wallets to connect with.
Once the wallet is connected the activeAccountId will be populated
Step 4: Use the Wallet Connection to Execute Contract Calls
Now that the wallet has been connected it is possible to access these props anywhere in the app through the useWallet()
method.
With selector.wallet() it's possible to get the current wallet instance and use it to execute Mintbase JS SDK methods to interact with smart contracts.
For more information on how to execute methods like transfer, mint on your very own token contracts deployed via our deployContract method or on how to list and buy from the mintbase market contracts check out the Make Your First Contract Call guide.
Join Us and Build the Future
Have feedback or perhaps need a hand? Reach out on our Telegram public developer support channel where we are happy to help!
Building something cool? Consider applying for a grant.\
\
Last updated