This is a next.js project. I detected metamask:
import detectEthereumProvider from "@metamask/detect-provider";
let provider;
if (typeof window !== "undefined") {
// for simplicity I am configured next.js for using top-level await
provider = await detectEthereumProvider();
}
// Provider is detected
console.log("provider", provider);
This is the function to send request to metamask. It is not throwing error:
const connect = async () => {
try {
await provider.request({ method: "eth_requestAccounts" });
} catch (e) {
console.log("error in request", e);
// location.reload();
}
};
I add click handler:
<Button onClick={connect}>Connect</Button>
Nothing is happening. so I chanded the click handler to:
<Button
onClick={() => {
// this is logging.
console.log("clicked to send request to Metamask");
connect;
}}
>
Connect
</Button>
It is logging that I clicked but it is not sending request to Metamask