Hi guys, i am new with the web3auth sdk, so am having a little troble tryng to export Web3Auth as i did with the web3 utilizing metamask to interact with smart-contracts. The way i did with metamask was the classical:
import Web3 from 'web3';
const { PROJECT_ID } = process.env;
let web3;
if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined') {
web3 = new Web3(window.ethereum);
} else {
const provider = new Web3.providers.HttpProvider(`https://polygon-mumbai.infura.io/v3/${PROJECT_ID}`);
web3 = new Web3(provider);
}
export default web3;
I did this so i could re-utilize the code and gain time while working on my projects. As i try to implement new features as Web3Auth and export it i start receving error like:
So here is my try to export Web3Auth so i could gain more time:
import Web3 from 'web3';
import { Web3Auth } from '@web3auth/modal';
const { PROJECT_ID } = process.env;
import { CHAIN_NAMESPACES } from '@web3auth/base';
const web3 = async () => {
if (typeof window !== 'undefined') {
const clientId = '';
const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: '0x13881',
rpcTarget: 'https://polygon-mumbai.infura.io/v3/', // This is the public RPC we have added, please pass on your own endpoint while creating an app
};
const webauth = new Web3Auth({
clientId,
web3AuthNetwork: 'testnet', // mainnet, aqua, cyan or testnet
chainConfig,
});
await webauth.initModal();
const provider = await webauth.connect();
const webbauth = new Web3(provider);
return webbauth;
} else {
const provider = new Web3.providers.HttpProvider(`https://polygon-mumbai.infura.io/v3/${PROJECT_ID}`);
const webbauth = new Web3(provider);
return webbauth;
}
};
export default web3;
I hope someone could help me with these problem