-
SDK Version: v7.3.2
-
Platform: Reactjs
“@walletconnect/sign-client”: “^2.10.6”,
“@web3auth/base”: “^7.3.2”,
“@web3auth/modal”: “^7.3.2”,
“@web3auth/wallet-connect-v2-adapter”: “^7.3.2”,
const [web3auth, setWeb3auth] = useState(null);
const [provider, setProvider] = useState(null);
const [loggedIn, setLoggedIn] = useState(false);
const [address, setAddress] = useState("");
useEffect(() => {
const init = async () => {
try {
localStorage.removeItem("Web3Auth-cachedAdapter");
const web3auth = new Web3Auth({
clientId,
chainConfig: flareConfig,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
});
// adding metamask adapter
const metamaskAdapter = new MetamaskAdapter({
clientId,
sessionTime: 3600, // 1 hour in seconds
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
chainConfig: flareConfig,
});
// we can change the above settings using this function
metamaskAdapter.setAdapterSettings({
sessionTime: 86400, // 1 day in seconds
chainConfig: flareConfig,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
});
// it will add/update the metamask adapter in to web3auth class
web3auth.configureAdapter(metamaskAdapter);
const defaultWcSettings = await getWalletConnectV2Settings(
CHAIN_NAMESPACES.EIP155,
[chainIdNum],
import.meta.env.VITE_WALLET_CONNECT_ID
);
console.log('wallet connect', import.meta.env.VITE_WALLET_CONNECT_ID)
const walletConnectV2Adapter = new WalletConnectV2Adapter({
adapterSettings: { ...defaultWcSettings.adapterSettings },
loginSettings: { ...defaultWcSettings.loginSettings },
});
web3auth.configureAdapter(walletConnectV2Adapter);
setWeb3auth(web3auth);
await web3auth.initModal({
modalConfig: {
[WALLET_ADAPTERS.OPENLOGIN]: {
label: "openlogin",
loginMethods: {
// Disable facebook and reddit
facebook: {
name: "facebook",
showOnModal: false,
},
reddit: {
name: "reddit",
showOnModal: false,
},
google: {
name: "google",
showOnModal: false,
},
discord: {
name: "discord",
showOnModal: false,
},
twitch: {
name: "twitch",
showOnModal: false,
},
apple: {
name: "apple",
showOnModal: false,
},
line: {
name: "line",
showOnModal: false,
},
github: {
name: "github",
showOnModal: false,
},
kakao: {
name: "kakao",
showOnModal: false,
},
linkedin: {
name: "linkedin",
showOnModal: false,
},
twitter: {
name: "twitter",
showOnModal: false,
},
weibo: {
name: "weibo",
showOnModal: false,
},
wechat: {
name: "wechat",
showOnModal: false,
},
sms_passwordless: {
name: "sms_passwordless",
showOnModal: false,
},
},
}, //Disable Torus Plugin
[WALLET_ADAPTERS.TORUS_EVM]: {
label: "TORUS_EVM",
showOnModal: false,
},
[WALLET_ADAPTERS.WALLET_CONNECT_V2]: {
label: "WALLET_CONNECT_V2",
showOnModal: true,
},
},
});
setProvider(web3auth.provider);
} catch (error) {
console.log("wallet--init--catch", error);
toast.error(
"Web3auth not initialized yet, please reload your browser",
{
position: toast.POSITION.BOTTOM_RIGHT,
toastId: "web3auth_toast",
}
);
}
};
init();
}, []);
const isConnected = async () => {
if (!web3auth) {
console.log("web3auth not initialized yet--isConnected");
return false;
}
return web3auth.status === "connected";
};
const web3Login = async () => {
if (!web3auth) {
console.log("web3auth not initialized yet");
return;
}
const web3authProvider = await web3auth.connect();
setProvider(web3authProvider.provider);
const connectedStatus = web3auth.status === "connected";
if (connectedStatus) {
setLoggedIn(true);
await getImmediateAccounts(web3authProvider.provider);
}
};
const web3logout = async () => {
if (!web3auth) {
console.log("web3auth not initialized yet");
return;
}
await web3auth.logout();
setLoggedIn(false);
const web3authProvider = await web3auth.logout();
setProvider(web3authProvider);
setAddress("");
setLoggedIn(false);
};
const getImmediateAccounts = async (provider) => {
if (!provider) {
console.log("web3auth not initialized yet");
return;
}
const rpc = new RPC(provider);
const acc = await rpc.getAccounts();
setAddress(acc);
return acc;
};
const getAccounts = async () => {
if (!provider) {
console.log("web3auth not initialized yet");
return;
}
const rpc = new RPC(provider);
const acc = await rpc.getAccounts();
setAddress(acc);
return acc;
};
VITE_WEB3AUTH_CLIENT_ID=‘’
VITE_CHAINID_NUM=14
VITE_CHAINID=‘0xE’
VITE_RPC_TARGET=‘https://flare-api.flare.network/ext/C/rpc’
VITE_DISPLAY_NAME=‘Flare’
VITE_BLOCK_EXPLORER=‘https://flare-explorer.flare.network/’
VITE_TICKER=‘FLR’
VITE_TICKER_NAME=‘FLR’
VITE_WALLET_CONNECT_ID=‘’
@TomTom @vjgee