HW3: Simple CardinalToken dapp

CS 359B Spring 2018

Deadline: April 23, 2018 11:00 am

Office hours: April 20, 4:30 pm - 5:30 pm, at Thornton 110. We recommend working on this assignment ASAP and coming to office hours to get help if needed. Worst case, you are welcome to come work on this homework during office hours, so we can help you.


To get you ramped up with the Ethereum development workflow and environment, we are releasing a short assignment which involves replicating the CardinalToken demo presented in the lecture, and then adding a simple feature on top of it.

Development with Remix

This part will use Remix for deploying smart contracts. Remix is easier to setup and understand, but not very powerful. It is not used for production environments.

1. Play with Remix

2. Connect Remix with Ganache

3. Simple web dapp using above components

Note on IDE: You can use any IDE you want. If you are looking for a recommendation for a simple IDE that supports Solidity, we recommend using Visual Studio Code. Unlike the other software of a similar name, this is actually a very lightweight and straightforward IDE based on ElectronJS. Immediately after installation, click “Install support for Solidity” on the “welcome message” and you will be good to go. If you want an embedded terminal, like the one we used in class, install the extension “Terminal”.

Development with Truffle

Close Remix. We will not use it anymore for deploying contracts. This part will use Truffle for deploying smart contracts. Truffle is more complex to setup and understand because it requires writing migrations and more. But it is more powerful and is generally the community’s choice for production environments.

4. Reproduce simple web dapp

5. Improve dapp

  1. Remember to compile your updated contract (`truffle compile`) and fix any errors (ignore the constructor warning)
  2. Remember to re-migrate your updated contract. Note: if you try to run `truffle migrate` it will say “Network up to date” because truffle already deployed your contract before and doesn’t know you changed it. Since you have made changes and you actually want to redeploy your contract, type `truffle migrate --reset` instead.
  3. If MetaMask works for the contract owner and crashes or experiences unexpected behavior for everyone else, then you have correctly completed the assignment. It means that your contract throws an error as expected. What happens is that MetaMask and Ganache are smart enough to detect the error before your code is even submitted as a transaction. However, MetaMask doesn't always handle contract errors well yet and reacts either by also crashing, or by displaying zero gas. A better behavior would have been that it informs you of the error. I am sure they will fix it.
  4. In general, if at any point Metamask does not correctly compute the gas for you and it shows all zeros, there is a problem. It most likely means that your contract throws an error early on and it does not even get posted on Ethereum, so the is no need to pay any gas. (Which may be the intended functionality when you are trying to mint tokens as a user who is not the contract creator.)
  1. If this functionality is not intended, then do not try to manually set the gas, it will not help. The problem is either with your code, or just simply an issue with metamask or ganache. To solve it try the following things:
  1. Close all browser tabs of your dapp. We notice problems with metamask when there are multiple tabs of different versions of the same dapp open.
  2. Look at your code for errors
  3. Try the workaround in the last slide

Submission - Github Classroom

We will be using github classroom for submitting code in this class. Use the link below to submit your answers and code for this homework:


(Answers go directly in the file README.md, which you can edit from the web, and code goes in the appropriate folders using git)

The above link will create a new private git repository for you in the class’ github account, and invite you to use it. Work directly on this repo, commit frequently. This way if you have questions, we can see the state of your code right away and provide you answers within that context.


You can update your submission as many times as you want before the deadline. Github is automatically sending us the version of your solution as it stands on the deadline.


It’s simple. Submit correct solutions to get full score.