I am using React and trying to open Metamask wallet to sign and get the address of the user. However I tried this code and I've clicked the button to trigger it, but nothing happen.
This is my code with a component (a page) called Metamask
import React from "react";
export const Metamask = () => {
const signMetamask = () => {
if (window.ethereum) {
window.ethereum.request({ method: "eth_requestAccounts" });
console.log("MetaMask is installed!");
}
};
return <button onClick={() => signMetamask()}>Open Metamask</button>;
};
If I click the button, I got the console.log result MetaMask is installed!
but the metamask window is not opened.
Please help to make it work. Thank you