MetaMask Extension — Secure Web3 Wallet & DApp Gateway
MetaMask is a browser extension that acts as a secure wallet for Ethereum and many EVM chains, and a bridge for decentralized applications (dApps). Below you’ll find an approachable guide for users and developers with best practices, installation steps, and example integration code.
Overview
MetaMask is a browser extension wallet that gives users control over their Ethereum accounts and keys while enabling websites to request permission to interact with those accounts. Instead of sharing private keys, dApps request transaction signatures and account permissions through the extension. This model preserves user autonomy — the wallet holds the keys, the dApp receives signed approvals only when the user consents.
MetaMask stores keys encrypted locally and never exposes them to websites. All signing occurs inside the extension; the dApp receives only signed messages or transactions after explicit user approval.
Websites request account access (e.g., `eth_requestAccounts`), and MetaMask prompts the user to approve. Approved websites can read the selected address and request signatures — but cannot move funds without additional signed transactions.
Install & Setup (Safe Steps)
Install only from the official source: go to metamask.io and choose your browser. The official download page redirects to the correct extension store entry for Chrome, Firefox, Edge, or Brave.
- Add the extension to your browser from the official store page.
- Create a new wallet or import an existing one using your Secret Recovery Phrase (seed) — ONLY do this in the extension, never on a website.
- Choose a strong local password to unlock the extension on your computer.
- Write your Secret Recovery Phrase on paper or a secure metal backup; never store it in cloud storage or as a screenshot.
Using MetaMask with dApps (User perspective)
When you visit a dApp, look for a “Connect Wallet” button. Clicking it triggers the browser to call the provider (MetaMask). MetaMask will show a popup that asks you to confirm which account you want to share and which permissions you grant. Review the payload and never approve unknown transaction data.
Common actions include:
- Connecting your account (reads your address).
- Signing a message for login or verification (no blockchain state change).
- Signing transactions that change on-chain state (tokens transfer, contract interaction) — these require explicit approval with gas details.
Developer integration (Minimal examples)
MetaMask injects a provider at `window.ethereum`. Below are two safe, commonly used examples: connect and sign a simple transaction or message.
// 1) Request account access (connect)
async function connectWallet() {
if (!window.ethereum) {
alert('Install MetaMask from https://metamask.io');
return;
}
try {
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
console.log('Connected account:', accounts[0]);
} catch (err) {
console.error('User rejected connection or other error', err);
}
}
// 2) Get chainId and handle network changes
const chainId = await window.ethereum.request({ method: 'eth_chainId' });
// Listen for changes
window.ethereum.on('accountsChanged', (accounts) => { /* update UI */ });
window.ethereum.on('chainChanged', (chainId) => { /* reload or re-init provider */ });
Important for developers: never ask users for private keys or recovery phrases. Use the provider to request approvals, and design UX that explains what a signed transaction does in plain language.
Privacy & Networks
MetaMask supports multiple networks and custom RPC endpoints. Be mindful: switching RPCs can expose different data to different nodes. Privacy considerations include metadata leakage and on-chain linkability — use best practices and privacy-preserving tools if required.
Tip: consider using separate accounts for different dApps to limit cross-site linkability.
Troubleshooting & common issues
If `window.ethereum` is undefined, MetaMask is not installed. Direct users to the official download page or show an install CTA.
If the user rejects a connection or transaction, catch the error and provide a clear explanation and retry option. Respect the user’s choice.