How to create your own blockchain-backed bank in only 30 minutes

Publish date:

Ryan Truman, Consultant, takes you through a hands on Blockchain demonstration, to help you add depth to your understanding of Blockchain.

How about some hands-on experience with blockchain? There are very few professionals with hands-on blockchain experience right now, meaning any amount of hands-on experience is a mighty fine feather to have in your cap. Furthermore, the brilliant thing about blockchain is how simple the technology behind the scenes can be.

Getting your hands dirty

The idea behind blockchain is what scientists call a paradigm shift. After conception it appears remarkably simple and obvious, yet it is radically different to anything that came before it. So, take advantage of this shift, learn how to create a blockchain system before anyone else realises how easy it is, and reap the rewards.

This blog is going to guide you in to making a “bank” backed by blockchain, without any prior development knowledge. Our bank is going to have limited functionality, and we are simply going to add the ability to transfer money between accounts. This isn’t anything flashy but the idea is to show you how the principles of blockchain function in reality.

We are going to be using Hyperledger Composer Playground, which is a great place to get started as you don’t need to worry about managing any underlying infrastructure, and it uses an industry leading open source framework. So, click on the link and let’s get started!

Step 1: Create a new network


Once you open Composer Playground, choose “Deploy a new business network”, as starting from scratch is the best way to build understanding.
The form that follows has little impact on your blockchain, enter information that matches your use case and choose “empty-business-network”.

 

 

 

Step 2: Defining your blockchain


Once you have created and named your business network you will be faced with today’s most daunting task. Defining how your blockchain functions – this is done using a .cto file which is Hyperledger’s own modelling language.

You can see the files used on your network on the left side of the screen

 

2.1 Creating your model.cto file

There are three artefacts you need to define when creating a blockchain: Assets, Participants, and Transactions. These are all defined in the model.cto file, so navigate there, delete the existing code and replace it with the following code:

/**
* Sample business network definition.
*/
namespace org.bankasset Account identified by AccNo {
o String AccNo
–> Customer owner
o Double balance
}participant Customer identified by customerId {
o String customerId
o String firstName
o String lastName
}transaction AccountTransfer {
o String AccNo
–> Account from
–> Account to
o Double amount
}

Optional: If you would like to understand how this code works, this page provides a good overview explaining the details of the .cto file.

 

2.2 Adding a script file

The next thing we need to add is a script.js file, this is a JavaScript file that works with the back end of Composer. So simply click add new file and add the following code as a script file:

/**

* Sample transaction processor function.

* @transaction

* @param {org.bank.AccountTransfer} accountTransfer – the account

* transfer

*/

function accountTransfer(accountTransfer) {

if(accountTransfer.from.balance < accountTransfer.amount) {

throw new Error(‘Insufficient funds!’);

}

accountTransfer.from.balance -= accountTransfer.amount;

accountTransfer.to.balance += accountTransfer.amount;

return getAssetRegistry(‘org.bank.Account’)

.then(function (assetRegistry) {

return assetRegistry.update(accountTransfer.from);

})

.then(function () {

return getAssetRegistry(‘org.bank.Account’);

})

.then(function (assetRegistry) {

return assetRegistry.update(accountTransfer.to);

});

}

 

2.3 Defining who can access your blockchain

The third and final thing you may want to add if you were doing this for a genuine system, would be an access control list (ACL). This is a file that defines who can do what on the blockchain. However, we aren’t going to be using it today

 

Step 3: Testing your blockchain


That’s it! Congratulations, you have now created your first blockchain network. Now your network has been created you can test a transaction and see how it hangs together.

Click the “Test tab” at the top of Hyperledger composer to can define customers, accounts and transactions by providing values for the attributes you specified in your model.cto file.

 

Now you have created the necessary artefacts for a transaction you can try to send money from one account to another. In the example to the right, I have sent £25.00 to Jimmy, identified by our account numbers. If you do the same, and you haven’t run in to any errors, the balance of your two accounts should have been updated too.

 

Congratulations, you’ve built your first blockchain application

Now that we have reached the end of the demo, you should have successfully created your first blockchain. Hopefully you agree that this wasn’t as intimidating as it sounds! Even though blockchain is cutting edge technology, it is built using simple principles, and thanks to organisations such as Hyperledger it is readily accessible and easy to use.

If you enjoyed this demo or are interested in the commercial applications of blockchain, or anything else about blockchain, get in contact with Capgemini Invent’s Blockchain Centre of Excellence, we are always happy to help.

 

Author


 

Ryan Truman

Ryan is a consultant in Capgemini Invent’s New Digital Services and Platforms team. Ryan joined Capgemini Invent in early 2017 and his primary focus is digital banking. He is currently delivering a Microsoft Azure transformation project for one the largest banks in the UK.

Related Posts

Customer Experience

Blockchain – A new era in utilities customer experience

Date icon October 23, 2019

Blockchain technology in utilities will transform customer experience and give them more...

Technology

Making it rain on the blockchain: 5 new business models the technology has enabled

Date icon July 19, 2019

Medy Ract, Consultant, shares a blog showcasing five business models enabled by blockchain

cookies.

By continuing to navigate on this website, you accept the use of cookies.

For more information and to change the setting of cookies on your computer, please read our Privacy Policy.

Close

Close cookie information