Create and execute blockchain smart contracts  

Create and execute smart contracts within a blockchain application using Hyperledger Composer

Last updated | By Ishan Gulhane


Organizations that use blockchain depend on trusted transactions to securely automate processes that were previously completed manually. In this developer pattern, you’ll learn how to use the Hyperledger Composer framework to create and execute smart contracts. Those contracts will run within a blockchain application built on Hyperledger Fabric.


Updated to support Hyperledger Fabric V1.1 and Hyperledger Composer V0.19

Note: This developer pattern is the second in a series of patterns designed to get you started with blockchain. For an overview of the series, see Build your first blockchain application.

In the first pattern of the series, you learned how to build a blockchain network. Now you’re ready to learn how to create and execute a smart contract within your blockchain application.

Blockchain is designed for multi-party business transactions, and organizations that use blockchain depend on trusted automatic transactions to do business. One of the most useful aspects of blockchain is its decentralization. Because it’s a decentralized system that exists between all permitted parties, there’s no need to employ intermediaries. In effect, you “cut out the middleman,” save time, and prevent potential disagreement about transactions.

Blockchain creators realized that the decentralized blockchain ledger could be used for self-executing or smart contracts. Smart contracts are used to exchange money, property, shares, or anything of value in a transparent, conflict-free way. Smart contracts not only define the rules and penalties around an agreement in the same way that a traditional contract does, but they also automatically enforce those obligations. No intermediary is required for a smart contract to be completed.

A good way to understand smart contracts is to compare the technology to a vending machine. Ordinarily, to complete a contract you’d go to an attorney, pay that attorney a fee, and wait to receive the document in question, whether a house closing agreement, a divorce decree, or any other “official” documentation. With the smart contract model, you simply drop a token into the vending machine–that is, the ledger–and your document (or candy bar) is provided to you, or deposited into your account. It’s a straightforward process requiring no additional intervention from anyone.

This developer pattern will show you how to use Hyperledger Composer to create a smart contract. You’ll execute the contracts on the blockchain app that you built in the first pattern of this series. If you’ve already completed the previous pattern, you know how useful Hyperledger Composer is for developing blockchain apps. Now you’ll take your blockchain skills to the next level by embedding and executing smart contract business terms.


  1. Install and instantiate the chaincode.
  2. Query and invoke the chaincode.
  3. View the transactions and the chaincode logs.

Related Blogs

Leveraging the power of AI at Unite Berlin

Last week, from June 19 – 21, we were at Unity’s premiere in Berlin: Unite 2018. This conference brought together Unity’s video game and development community. Unity touches 770 million gamers all over the world and is the market leader for consumer AR and VR use cases and is also rapidly emerging as the market...

Continue reading Leveraging the power of AI at Unite Berlin

Apps without privacy issues: Creating a blockchain wellness app on the cloud

Kubecoin takes fitness data directly from the phone health kit and places transactions on the "Kubechain." The app works anonymously and assigns a made-up identity to you, along with a randomly generated avatar. Your data can’t be traced to you, but you'll be able to see where your assigned avatar ranks on our leaderboard.

Continue reading Apps without privacy issues: Creating a blockchain wellness app on the cloud

Related Links


Check out the source code for Hyperledger Composer V0.19.3.