How to model smart contracts
A parametric insurance prototype
To demonstrate some aspects of designing and modeling smart contracts , I have chosen to implement a blockchain enabled prototype for a simple use case, which all of us know so well.
All of us know the feeling being nervous about the weather, when planning our next vacation, then we don’t want to spend our spare holidays budget on sitting indoor in a rainy destination.
Our future blockchain enabled prototype, let’s call it „SunnySide Insurance“ will tackle exactly this problem, and make it possible for us to get paid out on every day of our holidays based on the observed weather condition.
If it is rainy on that day, you will get paid out !!
No more fear of wasting your precious holidays budget because of bad weather !
The first step when designing software in general, is to understand and model the business Process , this is still valid also for our blockchain project.
The next step is to design the domain model, similar to what we have been doing on object oriented oriented design, only this time with contracts. we can call it „ contract oriented design“.
Here also most of the design principles like separation of concerns or the usage of code patterns and interfaces still apply, and still valuable for the same reasons.
Therefore the functionality is distributed in our use case into separate contracts and layers based on the different concerns in our system.
I used the following categories, to distribute the logic:
The resulting domain model of the smart contracts using the above categories looks like follows:
The last step is to start with the implementation of the system.
In this step there are in addition to the principles we know from the traditional software development ( OO, service oriented..) some new aspects which come into play with the use of public blockchains and contract-oriented languages.
Below is a table with 3 of those aspects and some of the guidelines which should be used in those cases.
Below you will find a template of the main contract „SunnySideInsurance“ mentioned in the above domain Model, to have a first idea of how the contract implementation structure in the solidity language looks like.
I will go through the aspects of the implementation in detail in a separate followup post on this blog.
When architecting software using smart contracts , most of the design principles for building software which we know are still valid, new aspects come into play, but there is no need to be intimidated by learning how to code with smart contracts on the blockchain.
If you need a fast track to become a smart contract developer, there are meanwhile several offers for courses and hands-on workshops for developers near you, which will bring you up to speed even faster.