A big thank you to Caspar Roelofs (Gimly) for writing an extended, original version of the learnings of creating Lisk.Bike. You can read the full blog post on Caspar’s blog.



Let me give you a gentle introduction to Lisk.Bike. The project, or also proof of concept, has been created by Blockchain030 which is located at Lisk Center Utrecht.



Lisk.Bike has been developed from the viewpoint of becoming a decentralized bike sharing platform, as described more extensively in this introductory blog by Gimly. The project wants to spark an active sharing economy but also grow the blockchain industry.

What is the definition of sharing economy?

An economic system in which assets or services are shared between private individuals, either free or for a fee, typically by means of the Internet.



The idea is to build one tool that allows anyone to participate in a bike sharing economy. When visiting Berlin, you’ll notice you have more than 15 bike sharing apps to choose from. To avoid installing multiple bike sharing apps that are controlled by different organisations, Lisk.Bike aims to open up this industry to regular users like us. Anyone can add their bike to the bike sharing economy while also reducing possible waste.



With the benefit of Lisk.Bike explained, the technical side of things remains.

Introduction to Lisk.Bike

Lisk.Bike allows anyone to register their bike with the application. This allows any user of the application to reserve a bike to take it for a ride.



Furthermore, the user has to deposit a fixed cost to the bike’s address. If the ride turns out to be shorter, the difference between the actual riding cost and the deposit will be returned to the user’s wallet.



Lastly, when users arrive at their destination, they have to lock the bike which is a custom transaction. Therefore, let’s explore the locking transaction on a technical level.

Technical exploration custom transaction Lisk.Bike

For the technical side of things, we’ll explore how the end rental custom transaction works. If you don’t have a lot of knowledge about custom transactions, read the following introductory post on the Lisk blog. You might want to check out the deep dive into custom transactions article as well.



Imagine Jan wants to get home from work and he locates a bike. He has sufficient funds in his account and he starts the rental of a bike close to his location. After riding home, Jan wants to lock the bike. Let’s see what happens in the applyAsset function of the custom transaction.



First of all, we need to retrieve some data from the ‘accounts’ entity. We are retrieving the bike account, renter account, and bike object.

Next, the code makes room for dynamic validation checks:

First of all, the bike object should exist. Secondly, the “rentedBy” property of the bike should hold an address as an “undefined” value. This would indicate nobody is renting the bike. Lastly, we need to check for the address that is sending the end rental transaction as the bike can only be returned from its own account or by the owner of the bike.

Next, the code calculates the total rental time. Using the property “billedHours”, we can determine how much the user has to pay considering the price per hour the bike owner has defined.

The next step tries to calculate how much of the initial deposit Jan will get back. When renting a bike, the user has to make an estimated deposit. For the end rental transaction, we calculate the difference between the actual amount Jan has to pay and his deposit. The difference will be returned to his account. Besides, the bike’s balance also gets updated to its new balance.

Lastly, the code sets the “rentedBy” property to an empty string so the bike can be rented out again.

Of course, we have to save the changes for the user and the bike. Therefore, we update both objects in the StateStore.

Final Words

The full code for Lisk.Bike can be explored in Lisk Center Utrecht’s GitHub repository. Let us know if you like this new type of short-form content exploring community projects or code snippets.



Lastly, we want to give Lisk Center Utrecht the opportunity to promote their blockchain + JavaScript conference.