How to set Moralis Provider when using Web3UIKit Connect Button?

Hey guys,

I am currently using the connect button from web3uikit to allow users of my dapp to connect to my contract. However, part of my dapp functionality requires the creation of a new contract instance using

const contract = new ethers.Contract(address, abi, provider)

Does anyone know what I can add as a provider? There is very little info on the web3uikit page.

Thanks in advance!

If you want to get the current web3 provider (when user connects their wallet), one way is to use web3 from the useMoralis hook which will be valid after connecting the wallet or authenticating through <ConnectButton>:

import { useMoralis } from 'react-moralis';

... 

const { web3, isWeb3Enabled } = useMoralis();

...
// can use isWeb3Enabled if you need to check if web3 provider is available 
const contract = new ethers.Contract(address, abi, web3);

const signer = web3.getSigner(); // if this is for making transactions

const contract = new ethers.Contract(address, abi, signer);