RainbowKit + Wagmi + Web3Auth + WalletService

I used Connector, But now widget dont appaer after login (Wallet Service). I’m using last version of all packages.

connect.tsx

import { darkTheme, lightTheme, RainbowKitProvider } from '@rainbow-me/rainbowkit';
import { WagmiProvider/*, http*/ } from 'wagmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { getDefaultConfig } from '@rainbow-me/rainbowkit'
import { getOtherWallets, getPopularWallets, getV2Wallets } from './rainbow';
import { getWalletClient as CoreGetWalletClient } from 'wagmi/actions';
import {
  Web3AuthInnerContext,
  Web3AuthProvider,
} from "@web3auth/modal-react-hooks";
import { useWalletServicesPlugin, WalletServicesProvider } from "@web3auth/wallet-services-plugin-react-hooks";
import web3AuthContextConfig, { web3auth } from './w3aContext';
import { WalletServicesPlugin } from '@web3auth/wallet-services-plugin';

export const wagmiConfig = getDefaultConfig({
  appName: 'Kalias',
  projectId: import.meta.env.VITE_WC_PROJECT_ID,
  chains: [eth],
  wallets: [getPopularWallets({ wallets: []/* particleWallets */ }), getV2Wallets(), getOtherWallets()],
  //transports: {
  // http, 
  //},
})

const queryClient = new QueryClient()

export const getWalletClient = () => CoreGetWalletClient(wagmiConfig);

export const WalletConnect = ({ children }: PropsWithChildren<unknown>) => {
  const { colorMode } = useColorMode();

   const walletServicesPlugin = new WalletServicesPlugin({
    wsEmbedOpts: {
      
    },
    walletInitOptions: { whiteLabel: { showWidgetButton: true, buttonPosition: "top-right", hideSwap:true }, },
  });

  const initWeb3Auth = useCallback(async () => {
    try {
     // await web3auth.init(); return error
    } catch (error) {
      console.error("failed to init w3a error: " + error);
    }
    try{
    web3auth.addPlugin(walletServicesPlugin);
    web3auth.getPlugin(walletServicesPlugin.name);
    
    } catch(e){
      console.log("failed to add plugin error: " + e); // no error
    }
  }, []);

  useEffect(() => {
    initWeb3Auth();
  }, [initWeb3Auth]);

  return (
    <WagmiProvider config={wagmiConfig}>
      <QueryClientProvider client={queryClient}>
        <Web3AuthProvider config={web3AuthContextConfig}>
          <WalletServicesProvider context={Web3AuthInnerContext}>
            <RainbowKitProvider theme={theme[colorMode]}>
              {children}
            </RainbowKitProvider>
          </WalletServicesProvider>
        </Web3AuthProvider>
      </QueryClientProvider>
    </WagmiProvider>
  );
};

RainbowWeb3authConnector.tsx

import { Web3AuthConnector } from "@web3auth/web3auth-wagmi-connector";
import { Web3Auth } from "@web3auth/modal";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
import { CHAIN_NAMESPACES, UX_MODE, WALLET_ADAPTERS, WEB3AUTH_NETWORK } from "@web3auth/base";
import { Wallet, WalletDetailsParams } from "@rainbow-me/rainbowkit";
import { createConnector as createWagmiConnector } from "wagmi";


const clientId = "xxx";

export const chainConfig = {
  chainNamespace: CHAIN_NAMESPACES.EIP155,
  chainId: '0x' + eth.id.toString(16),
  rpcTarget: eth.rpcUrls.default.http[0],
  displayName: eth.name,
  blockExplorerUrl: eth.blockExplorers.default.url,
};

const privateKeyProvider = new EthereumPrivateKeyProvider({ config: { chainConfig } });

const web3AuthInstance = new Web3Auth({
  clientId,
  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
  privateKeyProvider,
  uiConfig: {
    uxMode: UX_MODE.POPUP,
    modalZIndex: "99999999999999999",
  }
});


export const rainbowWeb3AuthConnector = (): Wallet => ({
  id: "web3auth",
  name: "social",
  rdns: "web3auth",
  iconUrl: "https://web3auth.io/images/web3authlog.png",
  iconBackground: "#fff",
  installed: true,
  downloadUrls: {},
  createConnector: (walletDetails: WalletDetailsParams) =>
    createWagmiConnector((config) => ({
      ...Web3AuthConnector({
        web3AuthInstance,
        modalConfig: {
          [WALLET_ADAPTERS.AUTH]: {
            label: "openlogin",
            loginMethods: {
              google: {
                name: "google",
                showOnModal: true,
                mainOption: true
              },
              email_passwordless: {
                name: "email_passwordless",
                showOnModal: true,
              },            },
          },
        },}
        )(config),
      ...walletDetails,
    })),
});

w3aContext.tsx


import { WEB3AUTH_NETWORK } from "@web3auth/base";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
import { Web3Auth, Web3AuthOptions } from "@web3auth/modal";
import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin";
import { chainConfig } from "./RainbowWeb3authConnector";

const clientId = "xxx";

const privateKeyProvider = new EthereumPrivateKeyProvider({
  config: {
    chainConfig,
  },
});

const web3AuthOptions: Web3AuthOptions = {
  chainConfig,
  clientId,
  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
  privateKeyProvider,
};

 const walletServicesPlugin = new WalletServicesPlugin({
  wsEmbedOpts: {},
  walletInitOptions: { whiteLabel: { showWidgetButton: true, buttonPosition: "top-right", hideSwap:true }, },
});

export const web3auth = new Web3Auth(web3AuthOptions);

const web3AuthContextConfig = {
  web3AuthOptions,
  plugins: [walletServicesPlugin],
};

export default web3AuthContextConfig;

Hi @kaliasdeveloper,

I noticed that the wallet services widget does show up in our example app. Could you please take a look at the configuration? The web3auth instance has all the code you need.

Here’s the code: web3auth-pnp-examples/web-modal-sdk/wagmi-examples/wagmi-modal-example/src/Web3AuthConnectorInstance.tsx at main · Web3Auth/web3auth-pnp-examples · GitHub

You can also try this app: https://wagmi-modal-example.vercel.app/

Hi @yashovardhan
I added connector to rainbow:

RainbowWeb3authConnector.tsx

export const rainbowWeb3AuthConnector = (): Wallet => ({
  id: "web3auth",
  name: "Google & Email",
  rdns: "web3auth",
  iconUrl: "https://web3auth.io/images/web3authlog.png",
  iconBackground: "#fff",
  installed: true,
  downloadUrls: {},
  createConnector: (walletDetails: WalletDetailsParams) =>
    createWagmiConnector((config) => ({
      ...Web3AuthConnectorInstance()(config),
      ...walletDetails,
    })),
});

Your suggestion here:

w3aConnectorInstance.tsx

import { Web3AuthConnector } from "@web3auth/web3auth-wagmi-connector";
import { Web3Auth } from "@web3auth/modal";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
import { CHAIN_NAMESPACES, WEB3AUTH_NETWORK, WALLET_ADAPTERS, UX_MODE } from "@web3auth/base";
import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin";

const clientId =
  "xxx";

export default function Web3AuthConnectorInstance() {
  // Create Web3Auth Instance
  const name = "My App Name";
  const chainConfig = {
    name,
    chainNamespace: CHAIN_NAMESPACES.EIP155,
    chainId: '0x' + eth.id.toString(16),
    rpcTarget: eth.rpcUrls.default.http[0],
    displayName: eth.name,
    blockExplorerUrl: eth.blockExplorers.default.url,
  };

  const privateKeyProvider = new EthereumPrivateKeyProvider({ config: { chainConfig } });

  const web3AuthInstance = new Web3Auth({
    clientId,
    web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
    privateKeyProvider,
    uiConfig: {
      //   useLogoLoader: true,
      //   logoLight: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
      //   logoDark: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
      //   defaultLanguage: "en",
      //   theme: {
      //     primary: "primary",
      //   },
      uxMode: UX_MODE.POPUP,
      modalZIndex: "99999999999999999",
    }
  });

  const walletServicesPlugin = new WalletServicesPlugin({
    walletInitOptions: {
      whiteLabel: {
        showWidgetButton: true,
        buttonPosition: "top-right",
        hideSwap: true
      }
    }
  });
  web3AuthInstance.addPlugin(walletServicesPlugin);

  const modalConfig = {
    [WALLET_ADAPTERS.AUTH]: {
      label: "openlogin",
      loginMethods: {
        google: {
          name: "google",
          showOnModal: true,
          mainOption: true
        },
        sms_passwordless: {
          name: "sms_passwordless",
          showOnModal: false
        }
      },
      showOnModal: true,
    },
  }

  return Web3AuthConnector({
    web3AuthInstance,
    modalConfig,
  });
}

connect.tsx

export const WalletConnect = ({ children }: PropsWithChildren<unknown>) => {
  const { colorMode } = useColorMode();
  return (
    <WagmiProvider config={wagmiConfig}>
      <QueryClientProvider client={queryClient}>
        <RainbowKitProvider theme={theme[colorMode]}>
          {children}
        </RainbowKitProvider>
      </QueryClientProvider>
    </WagmiProvider>
  );
};

App.tsx

const App = ({ children }: { children: React.ReactNode }) => {
  return (
    <ChakraProvider
      theme={theme}
      colorModeManager={customLocalStorageManager as any}
      toastOptions={{ defaultOptions: TOAST_BASE_OPTIONS }}
    >
      <ToastContainer />
      <WalletConnect>
        <GlobalModalManager.Provider>
          <ColorModeScript initialColorMode='dark' />
          <Layout>{children}</Layout>
        </GlobalModalManager.Provider>
      </WalletConnect>
    </ChakraProvider>
  );
};

On rainbow I see web3auth, I connect correctly but in the end I don’t see the widget of web3auth (Wallet Service)

mhh button seems built but is empty and I dont see it on page. I also setted svg as logo.
@yashovardhan

index.html

<div class="absolute top-4 right-4">
    <!---->
</div>

Hey @kaliasdeveloper

It is not possible for me to debug without being able to reproduce the issue. Is it possible for you to share a sample with me where you are facing this?

can you give your GitHub username and I share with you code @yashovardhan

Or please tell me if you want to do it another way @yashovardhan

I create this link with logs: @yashovardhan https://web3auth-test.vercel.app/

@yashovardhan any news

I created repo minimal if you need @yashovardhan

sorry, but I’m paying the scale plan but I haven’t used it yet. If you can’t fix it please let me know and I’ll understand @yashovardhan

Hey Kalias,

Sorry for missing your replies. I tried replicating this at that time but I wasn’t able to. I see you have created a minimal repository for this, can you share the link here directly? Also you can directly join our Office Hours and talk to us directly and we will solve this instantly during that time.

Can you send me github username?

invite sent in web3auth-test repo, let me know here if received @yashovardhan

received invite? @yashovardhan

Hey @kaliasdeveloper

I tested you app and was getting the issue. I have already raised it with one of our senior developers. I guess it is something in the configuration. In the meantime I have added wallet services in our rainbow kit example where it is working as expected: web3auth-pnp-examples/web-modal-sdk/wagmi-examples/rainbowkit-modal-example at main · Web3Auth/web3auth-pnp-examples · GitHub

Okay we got it fixed, it was a polyfill issue. I’m pushing the code on your repository.

oh thanks, I’m checking

It works now, I was curious to know why separating email and google in two connectors, the first does not work and the second does. If I exchange them the same thing. I left a comment on src- config-wallet-connect.tsx. Thanks in advance. @yashovardhan