Browse By

Block chain application development

Writing smart contract using Hyperledger Fabric
  • A smart contract in Hyperledger Fabric is a program, called chaincode.
  • Chaincode can be written in golang, nodejs or typescript.
  • Chaincode runs in a secured Docker container isolated from the endorsing peer process.
  • The web/mobile applications submit chaincode to hyperledger by calling commands such as “peer lifecycle install …”.
  • After that, applications can invoke or query the chaincode.

For example, one use case would be to get/update the value of the object in blockchain.

  • In one such use case, the chaincode would be created in advance and stored in cloud store (AWS S3).
  • The users would select the chaincode from the application UI, and submit the chaincode to the application backend.
  • The backend would then call hyperledger fabric commands to interact (deploy, invoke, query) with the chaincode in the context of hyperledger blockchain.
  • Any member of hyperledger network can activate the chaincode by submitting instantiation transactions to the network.
  • Any chaincode transactions that are validated are appended to the blockchain. Chaincode usually handles business logic that members of hyperledger network have agreed to.

After transaction is validated and committed, these transactions can then modify the blockchain world state accordingly. Hyperledger blockchain world state holds the current value of the attributes of business object as a unique blockchain state. That is useful because programs usually require the current value of an object. It would be cumbersome to traverse the entire hyperledger blockchain to calculate an object’s current value. With the world state, you just get the value directly from the world state.

A ledger world state containing two states. The first state is: key=CAR1 and value=Audi. The second state has a more complex value: key=CAR2 and value={model:BMW, color=red, owner=Jane}. Both states are at version 0.

The world state is implemented as a database. In Hyperledger Fabric, there are options of CouchDB or LevelDB for implementing world state database.

Ethereum vs Hyperledger  Fabric