3

I have just simple website in html on hosting. How to create login with metamask on website? Do I need use server?

1 Answer 1

2

You can interface with Metamask wallet using Web3js. I recommend using Reactjs instead of html. To make a login with Metamask you could use ERC-721 token authentication instead of usernames and passwords. React usually does require app or server hosting.

Example interfacing with Metamask:

import React, { Component } from 'react';
import Web3 from 'web3';

class App extends Component {
  async componentWillMount() {
    await this.loadWeb3()
    await this.loadBlockchainData()
  }

  async loadWeb3() {
    if (window.ethereum) {
      window.web3 = new Web3(window.ethereum)
      await window.ethereum.enable()
    }
    else if (window.web3) {
      window.web3 = new Web3(window.web3.currentProvider)
    }
    else {
      window.alert('Non-Ethereum browser detected. You should consider trying MetaMask!')
    }
  } 

  async loadBlockchainData() {
  ...
  }

Not the answer you're looking for? Browse other questions tagged or ask your own question.