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 ![]()
"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>;
}