Smart contracts are tiny computer programmes stored inside a blockchain, in this case, CENNZnet. In this article we will explore:
Smart contracts are small pieces of code that allow you to add additional logic to the core blockchain logic. They can be created and called by anyone on the network for a small fee. The code contains:
Smart contracts have some key characteristics:
Smart contracts don’t have to work in isolation, they can call upon other contracts to enact more functions or logic. There can even be a more complex chain of execution where a contract calls another contract that can call another contract, and so on.
Importantly, smart contracts can only run if they are called by a transaction, they never run on their own or in the background. In effect, they are dormant until a transaction triggers their execution, either directly or indirectly as part of a chain of contract calls. It is also important to note that smart contracts are not executed in parallel, they can connect in a chain but are run individually.
A critical security function of smart contracts is that they are charged every time they are triggered. This helps to prevent denial of service attacks and also prohibits pointless heavy code on the blockchain. This can however be a confusing concept for new users. To help ease them into the decentralised process, CENNZnet allows DApps to delegate their user’s fees.
Smart contracts allow DApp creators to publish additional logic and functionality on top of the existing core blockchain logic. They are the enablers of a DApps core functionality, connecting the UI to the blockchain and determining the business logic that can be enacted. Where normal apps connect to a backend system that defines some business rules and handles storage etc., for DApps this backend is replaced with a blockchain and a smart contract.
Each DApp on a blockchain can use one or more smart contracts to enable it to function on the chain. This smart contract will need to hold all of the DApps on-chain data and the defined set of rules that the DApp uses to transform data and complete transactions. It is VERY important that smart contracts are tested and secure before they are released onto the chain, as they essentially reveal all the key components of the DApp, it’s logic and data. This is fantastic for transparency and done correctly reinforces the trustless nature of blockchain, but if the contract exposes vulnerabilities, it can expose DApps and the blockchain to malicious attacks.
Users will then interact with the smart contract through the DApp’s UI. It is possible for users to bypass the UI and interact directly with the smart contract, however, to do this they would need to be very familiar with the backend code and blockchain development.
CENNZnet’s smart contracts have a few specific characteristics.