facebook

How to Customize the ConnectWallet Button in React SDK

Calender

1st December 2023

Clock

15 min read

Author
Yakshap Tyagi

Sr. Associate Consultant L1 - Frontend Development

Customize the ConnectWallet Button in the RainbowKit and React


RainbowKit is a React library designed to streamline the development of Connect Wallet user interfaces by offering a set of components that can be integrated with just a few lines of code. The library boasts compatibility with various wallets, including well-known ones such as Metamask, Rainbow, Coinbase Wallet, and WalletConnect. Notably, RainbowKit excels in customization, providing extensive options for tailoring the user interface to specific needs and preferences. The library also features a robust built-in theme for a visually appealing design.

Under the hood, RainbowKit leverages the capabilities of Ethers.js and Wagmi, two widely used libraries within the blockchain and cryptocurrency development space. These foundational technologies enable RainbowKit to seamlessly integrate wallet connectivity services into applications, ensuring a smooth and efficient user experience. The provided UI components come pre-equipped with support for multiple wallets, eliminating the need for developers to manually integrate and manage wallet functionalities. Overall, RainbowKit serves as a powerful wrapper, simplifying the incorporation of wallet connectivity services and enhancing the overall development process for blockchain applications.

 

Adding rainbowkit to our react app

 

npm install @rainbow-me/rainbowkit wagmi ethers

 

Now add the following code to app.js

 

import "../styles/globals.css";

import "@rainbow-me/rainbowkit/styles.css";

import {

  apiProvider,

  configureChains,

  getDefaultWallets,

  RainbowKitProvider,

} from "@rainbow-me/rainbowkit";

import { chain, createClient, WagmiProvider } from "wagmi";

 

const { chains, provider } = configureChains(

  [

    chain.mainnet,

    chain.polygon,

    chain.goerli,

    chain.rinkeby,

    chain.polygonMumbai,

  ],

  [apiProvider.fallback()]

);

const { connectors } = getDefaultWallets({

  appName: "My RainbowKit App",

  chains,

});

const wagmiClient = createClient({

  autoConnect: true,

  connectors,

  provider,

});

function MyApp({ Component, pageProps }) {

  return (

    <WagmiProvider client={wagmiClient}>

      <RainbowKitProvider chains={chains}>

        <Component {...pageProps} />

      </RainbowKitProvider>

    </WagmiProvider>

  );

}

export default MyApp;

 

RainbowKit Connect Button

This is the main component. It is responsible for rendering the connect/disconnect button, as well as chain-swapping UI.

 

import { ConnectButton } from '@rainbow-me/rainbowkit'; 

 

export const YourApp = () => { 

return <ConnectButton />;

 };

 

The ConnectButton component exposes several props to customize its appearance, including toggling the visibility of different elements.

 

  • Label

Use the label prop to set a custom ConnectButton text.

<ConnectButton label="Connect" />

  • Account Status
  1. Show account's avatar

<ConnectButton accountStatus="avatar" />

  1. Show account's address

<ConnectButton accountStatus="address" />

 

  • Chain Status
  1. Show chain's icon

<ConnectButton chainStatus="icon" />

  1. Show chain's name

<ConnectButton chainStatus="name" />

  1. Hide chain

<ConnectButton chainStatus="none" />

  • Show Balance

Used to show/hide the balance.

<ConnectButton showBalance={false} />

 

  • Responsive

This is used to define the responsive format of connect button

<ConnectButton showBalance={{ smallScreen: false, largeScreen: true, }} />

 

Dark Theme

Navigate to the app.js file in your project, and include the midnightTheme function from RainbowKit. Alternatively, you have the option to import the darkTheme function, which is a slightly subdued variant of the midnight theme. This step is crucial for mitigating eye strain and ensuring a more comfortable visual experience within your application.

 

import { midnightTheme, RainbowKitProvider, } from "@rainbow-me/rainbowkit";

Now pass this theme to the RainbowKitProvider;

 

<RainbowKitProvider chains={chains} theme={midnightTheme()}>

 

 

Table of Content

    Author Yakshap Tyagi

    Yakshap is an expert Frontend Developer with a strong focus on ReactJs technology. He has a deep understanding of several other web technologies such as JavaScript, HTML, CSS, Bootstrap, MongoDB, Node.js, Redux, and web3. He is a certified JavaScript professional with exceptional command over his skills. He has worked on various internal projects, including a Chat application, where he demonstrated his expertise in creating responsive, high-performing, and visually appealing interfaces. Yakshap is passionate about his work and enjoys taking up complex challenges while maintaining his eagerness to learn and grow.

    Sr. Associate Consultant L1 - Frontend Development

    bg bg

    What's Trending in Tech

    bg

    Our Offices

    India

    INDIA

    DG-18-009, Tower B,
    Emaar Digital Greens, Sector 61,
    Gurugram, Haryana
    122011.
    Unit- 117-120, First Floor,
    Welldone Tech Park,
    Sector 48, Sohna road,
    Gurugram, Haryana
    122018.
    USA

    USA

    30N, Gloud St STR E, Sheridan, Wyoming (USA) - 82801
    Singapore

    SINGAPORE

    10 Anson Road, #13-09, International Plaza Singapore 079903.

    By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.