Disclamation: This blog is for educational and personal purposes only, it is meant to let users understand blockchain technology.
Catching up!
From the previous post, we have discussed how blockchain mosaics can be used as an asset to represent tickets from RFID cards.
What are hardware wallets?
Hardware wallets usually come in the form of embedded devices, they have similar properties to a computer, except the fact that they can only run one program at a time, and their code is not retrievable as it is compiled to machine code (1s and 0s) into the system, which is really hard to decipher (advantage!)
One of the most famous hardware wallets are Trezor and Ledger Nano, however, their prices are really expensive for a beginner venturing into blockchain, so we are going to build our own under $13.

How does it work?
We will store our private and public key in our embedded device (Maker Uno in this case) and do a 6 pin entry authentication to retrieve it via serial communication using a C# Desktop Application. Then, we can use our account info to do a mosaic transaction via nodejs on our desktop application by running a shell script.
Getting Started
Materials:
- USB Micro B Cable
- Windows Laptop
Download the GitHub code from here and unzip it.

Hardware Setup
Connect the wires of your OLED and NodeMCU according to the schematic below:

Download and install the Arduino IDE

Launch the Arduino IDE and select File -> Preferences.

A window will pop out, paste the following link (http://arduino.esp8266.com/stable/package_esp8266com_index.json) into the Additional Boards Manager then click Ok.
Go to Tools -> Board and click Boards Manager

Search for esp8266 and hit the Install button.

Go to Manage Libraries.

Search SD1306 and download “ESP8266 and ESP32 Oled Driver for SSD1306 display”

Open the GitHub code you previously downloaded, and go to Hardlet -> Hardlet.ino, the Arduino should launch again with the code written. Select your board to NodeMCU 1.0 (ESP-12E Module)

Changing the code:
Paste in your private and public key in the variables key and pubkey.

Go to tools and select your USB Port (make sure the device is connected)

Click the “arrow left” icon on the Arduino to upload the code to the NodeMCU.

After the program has finished loading, you can see a simple 6 pin UI on your wallet.

Software
Open the folder and open a PowerShell window in the directory.

Execute the following command to install all needed libraries for the Nodejs, if you haven’t install Nodejs, please follow the instructions from the previous post.
>> npm install
Run the program
>> cd HardLet\HardLet\bin\Debug >> .\Hardlet.exe
A user interface should pop up, you can pin to Start or go to the HardLet\HardLet\bin\Debug directory and find the .exe file to execute the program next time.

Product
Connect your hardware wallet to your device, wait for the 6 pins to pop up on your screen, then only begin the connection. If the connection does not work, randomly press the connect/disconnect button to check if the pin arrangement randomizes (If it does, try the connection sequence again).
Explanation

To explain how it works, the Hardware wallet and the app is communicated through a serial port, if the UI sends a correct pin sequence to the Hardware wallet, the wallet will reply with the private key and public key.
The UI then attempts a REST API retrieval on the account info using the public key and private key from the wallet. The user is now able to do mosaic transaction.
The user only needs to key in the address of the receiver and number of mosaics it wants to send. When the transaction button is clicked, the app starts a NodeJS Shell (since C# NEM Catapult isn’t available yet), to do the mosaic transaction.
Once the transaction is successful, the user can check the confirmation status via REST API (also kept as a receipt) and can click a refresh button to see the decrease in mosaic amount.
Features:
- If the user disconnects or shutdowns the app halfway through the process, the hardware wallet is reset and the pins are randomized again.
- The seed of the random pin number is based on the voltage value of an analogue pin (which is a free connection), thus making the sequence hard to predict, even if so, you would need possession of the wallet to do so.