Metamask Wallet Connection – How to Connect Without a Server?

metamask

i need to connect my wallet to metamask, just i am using html + js (i have not to use any server neither other framework), then i implemented like this:

const connect = async () => {
  if (window.ethereum) { //check if Metamask is installed
    try {
    const address = await window.ethereum.enable(); //connect Metamask

but here if (window.ethereum) { i am getting always undefined

can i get up metamak

Best Answer

From Metamask's now archived FAQ.

Due to browser security restrictions, we can't communicate with dapps running on file://. Please use a local server for development.

"window.ethereum" is injected by MetaMask to a host, HTML opened on your browser is basically like a "text" file rendered by the browser, which won't trigger any browser extension's injection.

You don't need an actual server to test things out though, you can do it through localhost-ing.

The easiest one is through Visual Studio Code's extension - Live server.

Or if you're familiar with node.js.

cd <your-folder>

then from there:

npx http-server
Related Topic