Skip to content

Use Moralis as provider in React - await isn't allowed in non-async function error #1512

Answered by 0xCardiE
0xCardiE asked this question in Q&A
Discussion options

You must be logged in to vote

I used this one to solve it. Loads moralis provider right when needed.

useEffect(() => {
       if (isWeb3Enabled) {

           (async () => {
               const provider = await Moralis.enableWeb3();
               const raffleContract = new ethers.Contract(raffleAddress, abi, provider);
           })();
       }
   }, [isWeb3Enabled]);

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@0xCardiE
Comment options

@krakxn
Comment options

@0xCardiE
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by 0xCardiE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants