# MDA-Based Approach for Blockchain Smart Contract Development
## 3 MDA-Based Smart Contract Development Method
### Transformation from Blockchain CIM to Blockchain PIM  
Blockchain PIM represents the design model of the smart contract, specified without the specific details of the blockchain implementation platform. Blockchain PIM (Figure 3) encompasses UML class diagrams for smart contract structure specification and can also include UML state diagrams for behaviour specification. The Blockchain PIM profile contains not only standard UML metamodel elements, but also the <<SmartContract>> stereotype, an additional address type, and the <<pay>> stereotype, which denotes properties and operations concerning the cryptocurrency transactions. The profile also includes validation rules  
Figure 2: Blockchain CIM. Extended UML metamodel.  
that validate the model's conformance to the defined PIM structure for ensuring the correct input to subsequent transformations.  
The transition from Blockchain CIM to Blockchain PIM is performed by employing a model-to-model (M2M) transformation that maps input model elements to the output model elements, according to specified transformation templates. During this transformation (Figure 4), a smart contract structure is generated based on the CIM use case model. First, the PIM <SmartContract> class is created, and the CIM use cases that were associated with the <blockchain> actor are transformed to the PIM <SmartContract> class operations.  
Additionally, if the CIM domain class model is defined and includes the domain classes with the <on-chain> stereotype, these classes are directly transformed into the PIM <SmartContract> contained classes representing data structures. Furthermore, the rest of the domain class model is analysed, and if it is found that <on-chain> properties (or association ends which are also properties) exist not in an <on-chain> class, such CIM properties are transformed to the properties of the PIM contained class representing data structure. If in CIM, associations exist between <on-chain> classes, they are transformed to PIM associations between the PIM <SmartContract> contained classes representing data structures.  
Once the automated part of the transformation is complete, the developer can manually extend the PIM according to the logic specified in the CIM business processes. In terms of behaviour specification, the developer can define the smart contract state machines. The approach enables the specification of a smart contract behaviour as a classifier behaviour, while also supporting state machines mapped to a data structure, specified as an ownedBehavior. The state machine itself may include the states, transitions, and transition triggers specified as either call events or time events, and have additional behavioural logic included and specified as transition effects. Furthermore, the state machine outlines the transitional behaviour between states, which locks specific operation usage depending on the state the smart contract or data structure is in. The transitional logic may also include conditions specified either as transition guards or using junction, choice pseudostates.  
Figure 3: Blockchain PIM. Extended UML metamodel.  
The resulting Blockchain PIM contains the smart contract structure specification in the UML class diagram and can also incorporate the behaviour specification in the UML state diagram. This design model can be further transformed into Blockchain PSM for the platform of choice.