Skip to content

Instantly share code, notes, and snippets.

@johnexzy
Created November 9, 2022 12:33
Show Gist options
  • Save johnexzy/b69197f7b291b17f5142d329a4302e17 to your computer and use it in GitHub Desktop.
Save johnexzy/b69197f7b291b17f5142d329a4302e17 to your computer and use it in GitHub Desktop.
    async connectWallet() {
      try {
        // get injected ethereum from metamask
        const { ethereum } = window;
        if (!ethereum) {
          alert("Ethereum Provider does not exist, get metamask");
          return;
        }

        // request accounts
        const accounts = await ethereum.request({
          method: "eth_requestAccounts",
        });
        this.setCurrentAccount(accounts[0]);
      } catch (error) {
        console.log(error);
      }
    },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment