Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Smart Contracts are at the core of any blockchain implementation. The business logic is what drives many things in the blockchain, and Hyperledger makes it a little bit easier for us to implement Smart Contracts.
During many of our Blockchain Business Workshops, one area we heavily focus on is about Smart Contracts, and how they are executed in Hyperledger or any blockchain framework.
Before we jump in into its execution strategy, here is some essential information about Smart Contracts:
WHAT ARE SMART CONTRACTS?
Smart Contracts is the business logic that runs on a blockchain. The complexity of the Smart Contract depends on the strategy that you would use to solve your business problem with blockchain.
Smart Contracts is the business logic in a blockchain.
Smart Contracts are grouped into two, based on the use-case in which they are being implemented:
- On-chain Smart Contracts
- Installed Smart Contracts
On-chain Smart Contracts
These are executed when a transaction happens on the blockchain. And they are stored right inside the blockchain asĀ well.
Installed Smart Contracts
These Smart contracts are executed before the commit happens to the ledger or before the network is launched.
To understand a little bit more about Smart Contracts, take a look at the Hyperledger Architecture our CIO wrote about a few weeksĀ back.
HOW ARE SMART CONTRACTS EXECUTED?
To explain how Smart Contracts are executed in Hyperledger, hereās a diagram that would give you a very quick overview of theĀ flow:
Everything starts with the input block or the contract interpreter, where the ID of the contract is sent for a transaction request. Whenever the Smart Contract finds that the request is not valid, it rejects the contract, and then the transaction is committed to the blockchainās ledger.
Once this validation goes through, the transaction packet is sent to the consensus service, which sits in the middle of the processing unit. This is where the Smart Contract validates whether the transaction can be committed to the blockchain orĀ not.
This validation is not just a straightforward implementation of yes or no rules in the Smart Contract code. When validating a transaction, the Smart Contract validates two majorĀ things:
- Syntax Errors
- Logic Errors
Validating the syntax errors are very straightforward. But validating the logic errors are veryĀ complex.
When validating logic errors, Smart Contract validation turns to a policy-driven decision making. The best example would be to store the details of a double-transaction in the chain, for audit purposes for later use. This can be done if the policy requires you to doĀ that.
The best part about Hyperledger framework is the ability to handle Smart Contract in a unique way in each and every framework that itĀ has:
- Hyperledger Fabric
- Hyperledger Sawtooth
- Hyperledger Burrow
- Hyperledger Iroha
Pro Tip: When using Hyperledger for a large-scale transaction, using Hyperledger Sawtooth is preferred considering the way it handles the Smart Contracts cryptographically, rather than a straightforward validation.
How are Smart Contracts Executed in Hyperledger? was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.