Proj C 370: Stellar (15 pts)

What You Need

An Debian 10 64-bit server.

Background

IBM is backing the Stellar blockchain for use by banks:

IBM Backs a Dollar-Pegged Stablecoin Crypto Token on the Stellar Network

IBM Confirm Two Large Banks Using Stellar (XLM) for Foreign Exchange Corridors

Stellar is a complex system, with several different types of servers, designed to satisfy financial compliance regulations, as shown below.

Stellar is designed to solve the Byzantine Generals' Problem, in which a group of generals must agree on a mutual action, even if some of them are treacherous.

Stellar uses the Stellar Consensus Protocol, which is designed to have many desirable features, as shown below.

The figure below shows how a group of people decide what to order for lunch, using votes and constraints (called "v-blocking nodes"), eventually ratifying a decision.

This project takes you through connecting to the Stellar test network, creating accounts, and sending cryptocurrency from one account to the other, following this guide:

Exploring Stellar Lumens - Development Tutorial

These instructions are also very helpful:

https://github.com/michielmulders/stellar-js-sdk

Installing Node.js

On your Linux server, in a Terminal window, execute these commands:
sudo apt update
sudo apt install nodejs npm -y

Updating Node

To get the latest stable version of Node, execute this command:
sudo npm cache clean -f
Then execute these commands:
sudo npm install -g n
sudo n stable
PATH="$PATH"

Creating a Web Server

On your Linux server, in a Terminal window, execute this command:
nano hello.js
Enter this code, as shown below.
// Load HTTP module
var http = require("http");

// Create HTTP server and listen on port 8000 for requests
http.createServer(function(request, response) {

   // Set the response HTTP header with HTTP status and Content type
   response.writeHead(200, {'Content-Type': 'text/plain'});

   // Send the response body "Hello World"
   response.end('Hello World\n');
}).listen(8000);

// Print URL for accessing server
console.log('Server running at http://127.0.0.1:8000/');

Press Ctrl+X, Y, Enter to save the file.

Finding Your Server's IP Address

On your Linux server, in a Terminal window, execute this command:
ip addr show
Find your IP address, as shown below.

Running your Web Server

On your Linux server, in a Terminal window, execute this command:
node hello.js

Viewing the Web Page

In a Web browser, open your server's IP address followed by :8000, as shown below. You should see "Hello World", as shown below.

In the Terminal, press Ctrl+C to stop the Web server.

Using Express

Express automates the process of making Node apps.

On your Linux server, in a Terminal window, execute these commands:

mkdir myapp
cd myapp
npm init
Press Enter many times to accept the defaults, as shown below.

Now we need to install Express in the myapp directory and save it in the dependencies list of your package.json file.

In the Terminal window, execute these commands:

npm install express --save
cat package.json
npm complains about the node version being old, but it's OK to ignore that warning.

"Express" appears a dependency at the end of the file, as shown below.

Making a Custom Web Server

In the Terminal window, execute this command:
nano index.js
Enter this code, as shown below.
const express = require('express')
const app = express();

app.get('/', (req, res) => {
  res.send('Hello World! I am using Express!')
});

app.listen(8000, () => {
  console.log('Example app listening on port 8000!')
});

Press Ctrl+X, Y, Enter to save the file.

To run your server, in the Terminal window, execute this command:

node index.js
To view your page, in a Web browser, open your server's IP address followed by :8000. You should see the page, as shown below.

In the Terminal, press Ctrl+C to stop the Web server.

Installing the Express Application Generator

In the Terminal window, execute this command:
sudo npm install express-generator -g
In the Terminal window, execute these commands:
cd
express helloworld
This creates the app automatically, as shown below.

Execute this command to see its config file:

cat helloworld/package.json
This package has more dependencies, as shown below.

To start the package, execute these commands:

cd helloworld
npm install
DEBUG=helloworld:* npm start
This creates the app automatically, as shown below.

To view your page, in a Web browser, open your server's IP address followed by :3000. You should see a more modern-looking, prettier page, as shown below.

In the Terminal, press Ctrl+C to stop the Web server.

Installing Yarn

Execute these commands:
sudo npm install -g yarn

BAD
sudo apt update
sudo apt install curl git -y
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn -y

Installing the Stellar Demo App

Execute these commands:
cd
git clone https://github.com/michielmulders/stellar-js-sdk.git
cd stellar-js-sdk
yarn install
npm install
npm start
This loads and runs the Stellar test app. When I did it on Sept 18, 2021, I saw some error messages, as shown below, but it worked anyway.

To view your page, in a Web browser, open your server's IP address followed by :4000.

The page shows an error message, saying "Cannot GET /", as shown below. This is normal--the server does not use GET requests.

Creating Two Accounts

This demo app automatically creates two new accounts on the Stellar test network when it receives a POST request.

Leave the open Terminal window alone, running the app in Node.

Open a new Terminal window and execute this command to send a POST to the app:

curl http://127.0.0.1:4000 -d " "
The response is "Account A created!".

The original Terminal window shows balances for two newly created accounts, as shown below.

They both start with a balance of 10000 Lumens (the Stellar cryptocurrency). This is a testnet, however, so they aren't worth any real money.

Transferring Money

From the same terminal you used to run curl before, execute this command:
curl http://127.0.0.1:4000/payment -d " "
This transfers money from one account to another.

The response is "Transaction successful!".

The original Terminal window shows a lot of transaction information, including a URL to view the transaction, highlighted in the image below.

C 370.1: Viewing the Transaction (15 pts)

In a Web browser, open the transaction's URL.

The flag is the last field name, covered by a green rectangle in the image below.

Sources

https://www.stellar.org/developers/guides/get-started/create-account.html
https://nodesource.com/blog/installing-node-js-tutorial-ubuntu/
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Introduction
Stellar Quickstart Docker Image
https://codeburst.io/javascript-es-2017-learn-async-await-by-example-48acc58bad65
Consensus (computer science)

SCP images added 10-11-18
Integrated with Canvas 1-15-19