I am trying to add web3 wallet connect button onto my webpage but I am getting this error and I am not able to resolve it since a long time. It is a nextjs react application.
const InvitesPage: NextPage = () => {
let web3Modal: any;
useEffect(() => {
web3Modal = new Web3Modal({
network: 'rinkeby',
theme: 'light', // optional, 'dark' / 'light',
cacheProvider: false, // optional
providerOptions: providerOptions, // required
});
});
const classes = useStyles();
const { themeStretch } = useSettings();
const [connectedAccount, setConnectedAccount] = useState('');
const connectWeb3Wallet = async () => {
try {
const instance = await web3Modal.connect();
const provider = new ethers.providers.Web3Provider(instance);
const web3Accounts = await provider.listAccounts();
const network = await provider.getNetwork();
setConnectedAccount(web3Accounts[0]);
} catch (error) {
console.log(error);
}
};
const disconnectWeb3Modal = async () => {
await web3Modal.clearCachedProvider();
setConnectedAccount('');
};
return (
{!connectedAccount ? (
<ConnectIdentity
connectionType="Connect Wallet"
connected={false}
icon="eva:wallet-fill"
onClick={connectWeb3Wallet}
/>
) : (
<ConnectIdentity
connectionType="Disconnect Wallet"
connected={false}
icon="eva:wallet-fill"
onClick={disconnectWeb3Modal}
/>
)}
);
};
Inside the connectWeb3Wallet
function I get the following error -
Property 'providers' does not exist on type 'typeof import("/Users/encrypted_soul/code/..../node_modules/ethers/types/ethers")'.ts(2339)
The function above is almost identical to the readme of the package on npm - https://www.npmjs.com/package/web3modal?activeTab=readme
I am unable to understand why I am getting this error since providers is defined on ethers - https://docs.ethers.org/v4/cookbook-providers.html