Stellar

What You Need

An Ubuntu 16.04 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 Ubuntu server, in a Terminal window, execute these commands:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
sudo npm install npm --global

Creating a Web Server

On your Ubuntu 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 Ubuntu server, in a Terminal window, execute this command:
ip addr show
Find your IP address, as shown below.

Running your Web Server

On your Ubuntu 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 Ubuntu 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
"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
When you are prompted to, enter your password.

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.

Updating Node

To get the latest stable version of Node, execute this command:
sudo npm cache clean -f
When you are prompted to, enter your password.

Then execute these commands:

sudo npm install -g n
sudo n stable

Installing Yarn

Execute these commands:
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, as shown below.

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.

Viewing the Transaction

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

You see a lot of cryptographic data, as shown below.

Viewing Account History

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

The response is "History retrieved successful!".

The original Terminal window shows two transactions: first 300000001 XLM into the account, and then 20005682 XLM out of it, as shown below.

After those numbers, a message appears, dovered by a gray box in the image below. Enter that message into the form below to record your success!

Recording Your Success

Use the form below to put your name on the WINNERS PAGE.
Your Name:
Message:

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