[Archive] Problem with Multi Chain Wallets provider

:classical_building: Archived Content from Web3Auth Community

This topic was originally posted by TomTom on 6/7/2024.
This content has been migrated from our previous community forum to preserve valuable discussions.


Hello guys !

Currently trying to making work Multi Chain Wallets provider on the SDK Modal with NextJS by making my Context Provider Wrapper with my RPCs pass throught but It doesn’t work the way I I intended it unfortunately I might need some help on it :slightly_smiling_face:


"use client";

import { createContext, useContext, ReactNode } from “react”;
import { IProvider } from “@web3auth/base”;
import { useMultiChainStore } from “./useMultiChainProvider”;
import { Web3Auth } from “@web3auth/modal”;

interface MultiChainContextProps {
provider: IProvider | null;
loggedIn: boolean;
web3auth: Web3Auth | null;
login: () => Promise<void>;
logout: () => Promise<void>;
getAllAccounts: () => Promise<any>;
getAllBalances: () => Promise<any>;
getUserInfo: () => Promise<any>;
getAccounts: () => Promise<any>;
getBalance: () => Promise<any>;
sendTransaction: () => Promise<void>;
signMessage: () => Promise<void>;
}

const MultiChainContext = createContext<MultiChainContextProps | undefined>(undefined);

export const MultiChainProvider = ({ children }: { children: ReactNode }) => {
const multiChainStore = useMultiChainStore();

return (
<MultiChainContext.Provider value={multiChainStore}>
{children}
</MultiChainContext.Provider>
);
};

export const useMultiChain = (): MultiChainContextProps => {
const context = useContext(MultiChainContext);
if (!context) {
throw new Error(“useMultiChain must be used within a MultiChainProvider”);
}
return context;
};

import type {IProvider} from ‘@web3auth/base’

export default interface IRPC {

getChainId(): Promise<any>;
getAccounts(): Promise<any>;
getBalance(): Promise<string>;
sendTransaction(): Promise<any>;
signMessage(): Promise<any>;
getPrivateKey(): Promise<any>;
}

HI !

Did you check our multichain example ?

Also there is a multichain guide: Creating a Multichain Connection with Web3Auth and PnP no-modal SDK | Web3Auth