Metamask Address Exercise


In this exercise I want to you create a piece of code by yourself. Watch the lecture video to see me explaining the assignment. You probably need to use the web3.js documentation ( in order to solve this exercise. The most important thing is that you TRY, not that you get it 100% correct the first time. Good luck!


function mintAfterGame(noOfTokens) {
web3.eth.getAccounts(accounts).then(accounts => {[1], noOfTokens)
.send({from: accounts[1]}).on(‘reciept’, reciept => {
alert(‘Transaction Completed’);


Looks good. Maybe you need to change to accounts[0], but I’m not sure.


You are right @filip this do not work with accounts[1]. But I don’t understand why is it happening.


The array is zero-indexed. So the first (and only) address in the array is id nr 0.


This took a bit for me to figure out on my own but super happy to have figured it out without watching the solution video ;o)

                    var address;
                    web3.eth.getAccounts().then(acct => {
                        address = acct[0];
                        console.log("address: " + address);

                        if (address == null || address == "") {
                        console.log("No ETH Address Entered");
                        alert("No ETH Address Entered");
                        else {
                        console.log("Mint the winning tokens");
                        mintAfterGame(address, score);
                    coinsSent = true;

Found some interesting code I’m going to implement now that I got this working… it will check that metamask is installed, unlocked and if there is enough balance to process.


OK after watching the solutions video I see that even though my code works, it of course makes sense that this function go in the eth.js file etc… cleaning up my code to reflect this ;o)


Awesome, good job!!!