text: import React, { useEffect, useState } from "react";
  import { useMoralis } from "react-moralis";
  import MoralisDappContext from "./context";
  
  function MoralisDappProvider({ children }) {
    const { web3, Moralis, user } = useMoralis();
    const [walletAddress, setWalletAddress] = useState();
    const [chainId, setChainId] = useState();
    const abi = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"faucetCoin","outputs":[{"internalType":"bool","name":"sufficient","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getBalanceInEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sendCoin","outputs":[{"internalType":"bool","name":"sufficient","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
    const [contractABI, setContractABI] = useState(abi); //Smart Contract ABI here
    const [marketAddress, setMarketAddress] = useState('0x1be2FaFa94929d3bd2CD00645a42E60fbbd5C673'); //Smart Contract Address Here
    console.log('chainId--->', chainId, 'walletAddress--->', walletAddress);
  
  
    useEffect(() => {
      Moralis.onChainChanged(function (chain) {
        setChainId(chain);
      });
  
      Moralis.onAccountsChanged(function (address) {
        setWalletAddress(address[0]);
      });
      // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
  
    // eslint-disable-next-line react-hooks/exhaustive-deps
    useEffect(() => setChainId(web3.givenProvider?.chainId));
    useEffect(
      () => setWalletAddress(web3.givenProvider?.selectedAddress || user?.get("ethAddress")),
      [web3, user]
    );
  
    return (
      <MoralisDappContext.Provider value={{ walletAddress, chainId, marketAddress, setMarketAddress, contractABI, setContractABI }}>
        {children}
      </MoralisDappContext.Provider>
    );
  }
  
  function useMoralisDapp() {
    const context = React.useContext(MoralisDappContext);
    if (context === undefined) {
      throw new Error("useMoralisDapp must be used within a MoralisDappProvider");
    }
    return context;
  }
  
  export { MoralisDappProvider, useMoralisDapp };
  