Problem with the connect to web3 button and metamask

Viewed 184

Hello everyone, my application worked very well until today because the web3 button which connects to the network (metamask) no longer works. Do you have any solutions to my code? Thank you.

 export default function Home() {
  const [isConnectedWeb3, setIsConnectedWeb3] = useState(false);
  const [accounts, setAccounts] = useState([]);
  const [balance, setBalance] = useState(0);

  const [decimals, setDecimals] = useState(18);
  const [symbol, setSymbol] = useState("ETH");

  const [web3] = useState(
    new Web3(Web3.givenProvider || "ws://localhost:8545")
  );

  const [weiToSend, setWeiToSend] = useState(0);
  const [addressToSend, setAddressToSend] = useState("");

  const connectToWeb3 = useCallback(async () => {
    if (window.ethereum) {
      try {
        await window.ethereum.request({ method: "eth_requestAccounts" });

        setIsConnectedWeb3(true);
      } catch (err) {
        console.error(err);
      }
    } else {
      alert("Install Metamask");
    }
  });
0 Answers
Related