@maharshi
Package versions:
“@web3auth/base”: “^7.0.1”,
“@web3auth/coinbase-adapter”: “^7.0.2”,
“@web3auth/metamask-adapter”: “^7.0.1”,
“@web3auth/modal”: “^7.0.2”,
“@web3auth/web3auth-wagmi-connector”: “^5.0.0”,
Complete code including wagmi config:
const getWeb3AuthInstance = async (chains: Chain[]) => {
const web3AuthInstance = new Web3Auth({
clientId: environment.web3AuthClientId,
web3AuthNetwork: 'cyan',
sessionTime: 3600,
chainConfig: {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: '0x' + chains[0].id.toString(16),
rpcTarget: chains[0].rpcUrls.default.http[0],
displayName: chains[0].name,
tickerName: chains[0].nativeCurrency?.name,
ticker: chains[0].nativeCurrency?.symbol,
blockExplorer: chains[0]?.blockExplorers?.default.url ?? chains[0].rpcUrls.default.http[0],
},
enableLogging: false,
});
web3AuthInstance.configureAdapter(new MetamaskAdapter());
web3AuthInstance.configureAdapter(new CoinbaseAdapter());
const walletConnectSettings = await getWalletConnectV2Settings(
CHAIN_NAMESPACES.EIP155,
chains.map(chain => chain.id),
environment.walletConnectProjectId,
);
web3AuthInstance.configureAdapter(new WalletConnectV2Adapter(walletConnectSettings));
web3AuthInstance.configureAdapter(new OpenloginAdapter());
return web3AuthInstance;
};
const getWeb3AuthConnectorModalConfig = (): Record<string, ModalConfig> => ({
openlogin: {
label: 'openlogin',
loginMethods: {
discord: {
name: 'discord',
showOnModal: false,
},
twitch: {
name: 'twitch',
showOnModal: false,
},
apple: {
name: 'apple',
showOnModal: false,
},
line: {
name: 'line',
showOnModal: false,
},
kakao: {
name: 'kakao',
showOnModal: false,
},
weibo: {
name: 'weibo',
showOnModal: false,
},
wechat: {
name: 'wechat',
showOnModal: false,
},
sms_passwordless: {
name: 'sms_passwordless',
showOnModal: false,
},
},
},
[WALLET_ADAPTERS.TORUS_EVM]: {
label: 'torus_evm',
showOnModal: false,
},
});
const {chains, publicClient, webSocketPublicClient} = configureChains(getChains(), [publicProvider()], {
batch: {multicall: true},
});
const createBaseConfig = (connectors: Connector[]) =>
createConfig({
autoConnect: !!connectors.length && shouldWagmiAutoconnect(),
connectors,
publicClient,
webSocketPublicClient,
});
const baseConfig = createBaseConfig([]);
export const WagmiProvider: FunctionComponent<DefaultChildren> = ({children}) => {
const [config, setConfig] = useState(baseConfig);
useEffect(() => {
const run = async () => {
if (config.connectors.length > 0) return;
const web3AuthInstance = await getWeb3AuthInstance(chains);
const newConfig = createBaseConfig([
new Web3AuthConnector({
chains,
options: {
modalConfig: getWeb3AuthConnectorModalConfig(),
web3AuthInstance: web3AuthInstance!,
},
}),
]);
setConfig(newConfig);
};
run();
}, [config.connectors.length]);
return <WagmiConfig config={config}>{children}</WagmiConfig>;
};