How to Customize the ConnectWallet Button in React SDK

Posted By : Yakshap

Nov 20, 2023

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()}>

 

 

Leave a

Comment

Name is required

Invalid Name

Comment is required

Recaptcha is required.

blog-detail

November 23, 2024 at 01:09 am

Your comment is awaiting moderation.

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.

Chat with Us
Telegram Button
Youtube Button

Contact Us

Oodles | Blockchain Development Company

Name is required

Please enter a valid Name

Please enter a valid Phone Number

Please remove URL from text