Make sure you’re tracking the user’s correct ETH account
Prerequisite: A beginner-level understanding of Ethereum and web3.js.
User experience is one of the biggest roadblocks to onboarding users onto your decentralised application (DApp). Modern web browsers don’t support web3 by default, so most users have to interact with DApps via the Metamask browser extension.
Metamask allows users to alter the network and change their active wallet address from the extension.
Unfortunately, DApps won’t know when the user changes an account without specifically checking for it. This means that if a user changes accounts whilst using your DApp, they will be presented with out-of-date information relating to the previous account. This is like logging into your Facebook account and seeing the previous user’s dashboard. It is obviously unacceptable.
Fortunately, Metamask now allows you to listen for when a user changes their account in real-time with a simple piece of code.
Let’s assume that you have a function called getAccount() that connects to Ethereum and loads the active account being used. This occurs whenever the DApp is loaded.
Metamask fires an accountsChanged event upon account selection changing, which we can listen for. Figure 2 shows what the code for this looks like:
Using this event listener enables your DApp to get the latest wallet data in real-time, making your user experience slick and up to date. Figure 3 shows a DApp that retrieves the active wallet address and displays it in a button when the accountsChanged event is fired.
If you’re interested in Blockchain Development, I write tutorials, walkthroughs, hints, and tips on how to get started and build a portfolio. Check out some of these resources:
In the newer version metamask exposes an event that could be used to detect whether there's an account change as per new doc: window.ethereum.on('accountsChanged', function (accounts) { // Time to reload your interface with accounts[0]! })
What you do need to understand is that your accounts are controlled and created by your Secret Recovery Phrase. Each account is represented by a public address. Each account you create in MetaMask is derived from your Secret Recovery Phrase; therefore, your wallet contains one or more accounts.
Go via the account route: In the MetaMask Extension, click the account dropdown arrow and select the three vertical dots icon for the account you want to view on an explorer.
MetaMask allows you to manage multiple accounts — that is, multiple public addresses. Here's how you switch between them. Click on the account selector at the top of the screen.Here you'll see each of your previously created or imported accounts; click on the vertical dots next to each to view further details.
In short: if you're using MetaMask, your IP address and your Ethereum wallet address are getting logged with each transaction you make. But there is more. The moment you unlock the wallet it records ALL your addresses under the same IP. This makes it very easy to identify who you are and where you are located.
Your accounts in MetaMask are each represented by a public address (the 'public' side of your key pair), which you may have seen referred to incorrectly as a 'wallet address'. There is no such thing: there is only an account address.
Yes, you can have two or more Metamask crypto wallets. Within the wallet, you can create multiple addresses that function as a wallet. Each one can be imported to multiple devices as well.
A wallet reset essentially returns your MetaMask Extension or Mobile app to the state it was in when you downloaded it: it clears your Secret Recovery Phrase and your accounts from the software. After you execute a reset, you'll need to re-enter your Secret Recovery Phrase to get access to your wallet again.
Your Secret Recovery Phrase (SRP) is a unique 12-word phrase that is generated when you first set up MetaMask. Your funds are connected to that phrase. If you ever lose your password, your SRP allows you to recover your wallet and your funds.
While a Secret Recovery Phrase is used to create and restore your entire MetaMask Wallet, including all accounts created in that wallet, each account has its own private key. This key can be used to import that account, and that account only, into a different wallet.
Are several MetaMask accounts linked? Addresses are not in any way linked to one another. They can link the different addresses if they have access to your mnemonic phrase, extended private key, or extended public key, but you should never give this information out.
So if you're looking for a transaction and don't see it anywhere, check under the 'Internal Transactions' tab in Etherscan. To learn how to examine your account on Etherscan, start here. The actual transfer of funds shows up under the “To” field.
To catch MetaMask errors, we have to add a promise after the function call. This promise anticipates the hash of the transaction about to be broadcast to the blockchain.
Address: 5789 Michel Vista, West Domenic, OR 80464-9452
Phone: +97313824072371
Job: Education Orchestrator
Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building
Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.
We notice you're using an ad blocker
Without advertising income, we can't keep making this site awesome for you.