Skip to content

Instantly share code, notes, and snippets.

@starlabman
Created October 10, 2022 13:49
Show Gist options
  • Save starlabman/373442ae4453db90bc0266c2eae5b377 to your computer and use it in GitHub Desktop.
Save starlabman/373442ae4453db90bc0266c2eae5b377 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Connect to crypto wallet</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.7.4-rc.1/web3.min.js"></script>
</head>
<body>
<script>
/* To connect using MetaMask */
async function connect() {
if (window.ethereum) {
await window.ethereum.request({ method: "eth_requestAccounts" });
window.web3 = new Web3(window.ethereum);
const account = web3.eth.accounts;
//Get the current MetaMask selected/active wallet
const walletAddress = account.givenProvider.selectedAddress;
console.log(`Wallet: ${walletAddress}`);
} else {
console.log("No wallet");
}
}
</script>
<input type="button" value="Connect Wallet" onclick="connect();" />
</body>
</html>
@starlabman
Copy link
Author

Web3 Metamask Login Version 2 https://github.com/starlabman/Web3-Metamask-Login

I am an application developer, I do back-end and front-end programming, and server configuration and management. I hesitate to say "full stack developer", a term popularized some time ago, which has become controversial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment