Skip to content

RainbowKit

支持版本: >=1.1.0
支持时间: 2023.10.15

链及标准

  • ETH
  • 钱包标准支持:EIP-1193、EIP-6963

安装

Rainbow 只支持 React Rainbow 依赖 viem 和 wagmi

js
npm init @rainbow-me/rainbowkit@latest
# or
pnpm create @rainbow-me/rainbowkit@latest
# or
yarn create @rainbow-me/rainbowkit
npm init @rainbow-me/rainbowkit@latest
# or
pnpm create @rainbow-me/rainbowkit@latest
# or
yarn create @rainbow-me/rainbowkit

安装RainbowKit及其对等依赖项

js
npm install @rainbow-me/rainbowkit wagmi viem@2.x @tanstack/react-query
npm install @rainbow-me/rainbowkit wagmi viem@2.x @tanstack/react-query

开发配置

js
import '@rainbow-me/rainbowkit/styles.css';

import {
  getDefaultConfig,
  RainbowKitProvider,
} from '@rainbow-me/rainbowkit';
import { WagmiProvider } from 'wagmi';
import {
  mainnet,
  polygon,
  optimism,
  arbitrum,
  base,
  zora,
} from 'wagmi/chains';
import {
  QueryClientProvider,
  QueryClient,
} from "@tanstack/react-query";

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

import { connectorsForWallets } from '@rainbow-me/rainbowkit';
import '@rainbow-me/rainbowkit/styles.css';

import {
  getDefaultConfig,
  RainbowKitProvider,
} from '@rainbow-me/rainbowkit';
import { WagmiProvider } from 'wagmi';
import {
  mainnet,
  polygon,
  optimism,
  arbitrum,
  base,
  zora,
} from 'wagmi/chains';
import {
  QueryClientProvider,
  QueryClient,
} from "@tanstack/react-query";

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

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

钱包选项配置

js
import {
  rainbowWallet,
  bitgetWallet,
  walletConnectWallet,
} from '@rainbow-me/rainbowkit/wallets';

//for users without bitget wallet
let customWallets = [rainbowWallet, walletConnectWallet];
if(!window.bitkeep){
  customWallets.unshift(bitgetWallet);
}
const connectors = connectorsForWallets(
  [
    {
      groupName: 'Recommended',
      wallets: customWallets,
    },
  ],
  {
    appName: 'My RainbowKit App',
    projectId: projectId,
  }
);
import {
  rainbowWallet,
  bitgetWallet,
  walletConnectWallet,
} from '@rainbow-me/rainbowkit/wallets';

//for users without bitget wallet
let customWallets = [rainbowWallet, walletConnectWallet];
if(!window.bitkeep){
  customWallets.unshift(bitgetWallet);
}
const connectors = connectorsForWallets(
  [
    {
      groupName: 'Recommended',
      wallets: customWallets,
    },
  ],
  {
    appName: 'My RainbowKit App',
    projectId: projectId,
  }
);

初始化

js
const config = getDefaultConfig({
  connectors,
  appName: 'My RainbowKit App',
  projectId: projectId,
  chains: [mainnet, polygon, optimism, arbitrum, base, zora],
  ssr: false, // If your dApp uses server side rendering (SSR)
});

const queryClient = new QueryClient();

export default function RainbowDemo() {
  return (
    <WagmiProvider config={config}>
      <QueryClientProvider client={queryClient}>
        <RainbowKitProvider>
          <ConnectButton />
        </RainbowKitProvider>
      </QueryClientProvider>
    </WagmiProvider>
  );
};
const config = getDefaultConfig({
  connectors,
  appName: 'My RainbowKit App',
  projectId: projectId,
  chains: [mainnet, polygon, optimism, arbitrum, base, zora],
  ssr: false, // If your dApp uses server side rendering (SSR)
});

const queryClient = new QueryClient();

export default function RainbowDemo() {
  return (
    <WagmiProvider config={config}>
      <QueryClientProvider client={queryClient}>
        <RainbowKitProvider>
          <ConnectButton />
        </RainbowKitProvider>
      </QueryClientProvider>
    </WagmiProvider>
  );
};

更多功能

参考官网 https://www.rainbowkit.com/zh-CN/docs/custom-connect-button

  • 自定义 ConnectButton
  • 自定义主题
  • 自定义钱包列表
  • 自定义钱包
  • 自定义链
  • 自定义应用信息
  • 自定义头像
  • 自定义认证
  • 钱包按钮
  • 酷炫模式

相关阅读