lisk.bike workshop instructions - liskcenterutrecht/lisk.bike GitHub Wiki

Instructions Lisk.Bike Workshop

Welcome to the step-by-step guide to using the Lisk.Bike application with Lisk Alpha SDK. This app showcases the possibilities of Lisk custom transactions in the real world.

Before you can use the Lisk SDK you have to install some packages. Follow the Lisk tutorial Hello World if you want to install the software on your own pc.

1. Install all dependencies.

A good tutorial might follow here. Otherwise, just follow the 'Hello world' link as mentioned above.

2. Take a look at the running blockchain process

Your VPS is a node that runs its own instance of the Lisk.bike blockchain. You can see the new blocks being forged.

pm2 logs blockchain

Ctr+C ends the display

3. Explore the source code and get familiar with the VPS

The application is a combination of JavaScript files for the app itself and the custom transactions.

The github repository is a good place to explore the project structure:

https://github.com/liskcenterutrecht/lisk.bike

Update the tutorial files

First make sure that you have the latest version of the tutorial files:

cd ~/lisk-bike/  
git pull

If this gives you an overwrite error, please use these commands:

git fetch --all  
git reset --hard origin/master  

Custom transactions

On the VPS, the blockchain related files are located @ ~/lisk-bike/app/imports/api/lisk-blockchain

You find the custom transaction files here:

cd ~/lisk-bike/app/imports/api/lisk-blockchain/transactions

To see the custom transaction types, type in ls to view all of them.

Local Blockchain

On the VPS, a local lisk blockchain node is running: this is done in the background using the pm2 process manager: You can inspect the process by typing

pm2 logs blockchain

Ctr+C ends the display

Now restart the blockchain to incorperate any changes from github

pm2 restart blockchain

Also you can explore the blockchain with a local instance of the lisk explorer. Navigate to

http://<vps name>.lisk.bike:6040

to see what happens on the blockchain.

For this tutorial, we will use this local blockchain to do all transactions. This is set up using the node enviroment settings. For this you have to edit the file .ENV and change the HTTP_HOST setting to point to your local node:

cd ~/lisk-bike/app/imports/api/lisk-blockchain/tests
nano .env
change HTTP_HOST=brainz.lisk.bike
to HTTP_HOST=<your vps name>.lisk.bike

save the changes with ctrl-X, yes, overwite existing file

Start with a clean blockchain

If at any point in this tutorial you want to reset the blockchain (remove added bikes and transactions), you can use the following commands:

pm2 stop blockchain
sudo -u postgres psql -c "DROP DATABASE lisk_dev;"
sudo -u postgres psql -c "CREATE DATABASE lisk_dev OWNER lisk";
pm2 start blockchain
rm ~/lisk-bike/app/imports/api/lisk-blockchain/tests/accounts/*.json

4. Interact with the blockchain with JavaScripts

We created JavaScript files to use the transactions. You find these files in the directory “tests” in the directory “lisk-blockchain”.

cd ~/lisk-bike/app/imports/api/lisk-blockchain/tests

You start with an empty setup. So follow the instructions to work through the whole flow of the system we created for Lisk.Bike.

4.1 Create wallets

Create three wallets: one for the user that owns the bicycle, one for the bicycle itself and one for the user that will rent the bicycle. The console shows you the created wallet.

The command takes the name of the new account as parameter: This name is used to store your account info in a file on disk, so that you don't have to remember the corresponding public and private keys and blockchain address.

node create-account.test.js owner  
node create-account.test.js bike1
node create-account.test.js renter

What just happened?

  • You created an account using a passphrase.
  • Then you created a custom (faucet) transaction with the address and public key from your account.
  • Next you signed the transaction with the private key from your account.
  • The transaction was sent to the blockchain using the APIClient.
  • Finally you looked up the transaction on the blockchain using lisk-explorer.

4.2 Register your bicycles

Now you can let the world know that you want to share your bicycle: You do this by registering your bicycle account on the blockchain.

The command takes two parameters: name of the owner account and name of the bicycle account. Use the same names that you used in the previous step.

node create-bike.test.js owner bike1

The console shows you the characteristics of the bike as registered on the blockchain.

If you want to add multiple bicycles to your fleet, you can register more bike wallets and create additionals bicycles.

What just happened?

  • You created a custom transaction that tagged the bicycle account.
  • Next you signed the transaction with the private key from the bike owner account.
  • The transaction was sent to the blockchain using the APIClient.

4.3 Look at the blockchain

Now you can check the bicycles that are present on the blockchain. Keep in mind that the list shows all the bicycles in the ecosystem, so there can be more than just your own bikes!

node list-bikes.test.js

If you want to see more details, try

node list-bikes.test.js details

This is also a good time to look at the accounts that you are using. Use the command below to check the owner, renter and bike accounts. Look at the account state and the transactions that have been recorded.

node list-account.test.js owner
node list-account.test.js bike1
node list-account.test.js renter

4.4 Rent a bicycle

Now it is time to rent a bicycle: Use the renter account to rent one of the available bicycles. You can use the list-bikes.test.js script to find one. Look at the rental state at the end of the lines to find available bikes.

node rent-bike.test.js renter bike1

The console shows you which wallet rented which bike. If you’re already renting a bike or are trying to rent a bike that is already rented, you get an error message.

Now take another look at the accounts that you are using. Can you spot the differences?

node list-account.test.js owner   
node list-account.test.js bike1
node list-account.test.js renter

4.4 Return the bicycle

Lock the rented bicycle using the script below.

node return-bike.test.js bike1

The console gives you a message about returning the bike. The payment is automatically made and the remainder of the deposit comes back to the renter’s wallet. Use the list-account.test script to check the transactions.

5. Explore the source code of a custom transaction

Now let take a look at the internals. 'cd' to the transactions folder:

cd ~/lisk-bike/app/imports/api/lisk-blockchain/transactions

When you take a closer look into the custom transaction files, you see that they have their own identifier (this is called a TYPE). This helps to find the transactions on the blockchain.

Use the nano editor on the VPS to explore the source code:

nano create-bike.js

What is the TYPE of the custom transactions that Lisk.Bike uses?

  • create-bike.js :
  • faucet.js :
  • rent-bike.js :
  • return-bike.js :
  • update-bike-location.js :

6. Find the custom transaction on the blockchain

In the Lisk block explorer, you can investigate the transactions that get written into the blockchain.

a. Find the transactions you did at step 4 in the block explorer. Go on your local machine to explorer.example.com

Another way to explore the blockchain is to use the Lisk API to ask for information.

b. Get a list of the transactions you did at step 4 with the use of the API. Go on your local machine to:

http://<vps name>.lisk.bike/api/transactions

http://<vps name>.lisk.bike/api/transactions?type=<the TYPE you want to see>

⚠️ **GitHub.com Fallback** ⚠️