Learn step-by-step how to turn a regular template app into an onchain app with a wallet connection.
.
, if you want to add the project to the root of a folder you’ve already created. Otherwise, name your project. Select each option in the generation script as you see fit. We recommend the following selections:
src/
directory?: Yesyarn dev
to make sure it generated correctly.
app/layout.tsx
, if you followed the recommended setup options. As you want the blockchain provider context to be available for the entire app, you’ll add it here.
You’ll need to set up your providers in a second file, so that you can add 'use client';
to the top. Doing so forces this code to be run client side, which is necessary since your server won’t have access to your users’ wallet information.
'use client';
directly in layout.tsx
!app
folder called providers.tsx
.
'use client';
to the top of the file.
Continue with the imports:
styles.css
differently. You’ll know this is the case if you get ugly text at the bottom of the page instead of a nice modal when you click the connect button.getDefaultConfig
for now, to get started. See our guide on Connecting to the Blockchain for more information on blockchain providers.
projectId
from Wallet Connect Cloud, which you can get for free on their site. Make sure to insert it in the appropriate place.
QueryClient
and returns props.children
wrapped in all of your providers.
layout.tsx
. Import your Providers
, being careful if you use auto-import as there are many other things with similar names in the list. Wrap the children
in your return
with the new Providers
.
RainbowKitProvider
. Common practice would be to place the button in your app’s header. Since the Next.js template doesn’t have one, you can just add it to the top of the automatically generated page, rather than spending time implementing React components.
Open up page.tsx
, and import the ConnectButton
:
ConnectButton
component at the top of the first <div>
:
yarn dev
, and you should be able to use the RainbowKit connect button to connect with your wallet and switch between networks.
You use the Connect Button props to modify its properties, or you can customize the connect button extensively. Some users dislike having the connect button display their token balance. Try disabling it with: