🔴 What are smart contracts in Cardano? I have spent several hours understanding this topic 🙄 Here is the introduction 💬👇
🔴 Cardano is a 3rd generation blockchain, a programmable blockchain platform. Cardano is a system analogous to Ethereum – a programmable computer. However, the data architecture that makes up the blockchain in Cardano, is analogous to… Bitcoin. What does this mean?
🔴 Cardano’s data architecture is based on EUTXO. This means extended (extended) UTXO. To understand UTXO, we need to know the classical blockchain data model.
🔴 The data in each blockchain is stored in cryptographically secured blocks. The blocks have transactions, i.e. descriptions of the changes to be made to the blockchain. A transaction is, for example, the transfer of a cryptocurrency from one address to another, but also the execution of an exchange on the decentralised Uniswap exchange, which triggers a ‘smart contract’ by storing data on the blockchain about the purchase/sale performed. The data in the blocks create a history of changes on the blockchain, with the consensus algorithm and cryptography guaranteeing its security and immutability.
🔴 Ethereum, as a programmable blockchain has, in addition to the blocks, another special space described as the ‘system state’ (world state). This always reflects the current, latest state of the data. For example, by sending 3 times 1 Ether from account A, to B – in the world state, B will finally have 3 Ether’s, although we will find 3 separate state change transactions in the blocks. In the same way, the data updated by the smart contract changes. This data structure makes it easy to read, data access is fast (indexed). Each node in the network has its own independent ‘world state’, which should be the same after processing all transactions at all nodes.
🔴 Wanting to check the state of your Bitcoin holdings by address X, you need to… scan every block and every transaction in the Bitcoin blockchain. Why? Because Bitcoin does not have a world state. Just like Cardano. The smallest data structure carrying information in Bitcoin and Cardano is UTXO. In Bitcoin, the data that the UTXO holds is information about the “amount of Bitcoin” available to spend. If a UTXO with the notation “1 BTC” is assigned to an address, the address controls 1 BTC. Cardano’s EUTXO, in addition to information about the amount of cryptocurrency, also holds data and even the smart contract logic itself.
🔴 EUTXO makes the data operation (and the programme in Cardano) a literal iteration, going through a chain of related UTXOs. A UTXO can be issued and, when issued, is marked as ‘out of date’, but a new UTXO is created, having an updated data state. The operation of smart contracts in Cardano, is precisely the process of creating new EUTXOs and marking old ones as obsolete.
🔴 In order to let you understand the construction of smart contracts (contracts) in Cardano, I will explain the construction and operation of a classic contract, i.e. as we can implement in Ethereum, the first and still market-leading programmable blockchain. A contract in Ethereum is a “small” computer program, i.e. a set of data and instructions to process this data, to perform certain operations on it. Such a contract, as a ‘package’, we have the possibility to upload to the blockchain network. Such a program becomes an immutable part of the blockchain and, from the moment it is loaded, the blockchain guarantees its immutability (the instructions of the contract cannot be changed). It also becomes globally accessible and visible to the entire blockchain network. The contract is given a unique address on the blockchain network. Knowing this address, we are able to interact with this contract, i.e. run its functions, which can, for example, write new data to the blockchain or read existing data (previously written by the contract). Depending on the security features of the contract (we program them), other users of the blockchain and even other contracts can interact with our contract. To summarise: the idea is simple – contracts in Ethereum are programs that exist on the blockchain.
🔴 Contracts in Cardano are not individual programs loaded into the blockchain, accessible at a specific address. In Cardano, we write small blocks (in the form of EUTXO) to the blockchain that represent either data or logic/rules of use/property rights to that data. Invoking a smart contract, involves writing a transaction to the blockchain in which we indicate existing data blocks (EUTXOs), blocks with rules for processing them (script EUTXOs) and data ‘unlocking’ existing data blocks. The ‘unlock’ data provided in a transaction, unlocks the data blocks (and allows new ones to be written to the blockchain) only if they match (unlock) the rule blocks. This separation of data from rules, the recording of small, independent blocks in the blockchain (EUTXO) and the idea of ‘unlocking’ is what Cardano is all about.
🔴 Plutus, or smart contracts in Cardano. Here are the basics of creating web3 solutions on Cardano 💬👇
🔴 Plutus is the smart contracts platform in Cardano. A rather broad term, as the name ‘Plutus’ is by Cardano part of several important Cardano products/technologies including Plutus Core and Plutus Framework.
🔴 Web3 solutions for Cardano are developed in Haskell. The program code is compiled (difficult word) into Plutus Core, which is the ‘language’ understood by the Cardano blockchain. From the perspective of the user, the programmer – about Plutus Core only worth knowing, we use Haskell 😉
🔴 Web3 applications for Cardano have a different architecture than applications for Ethereum. In web3 Ethereum there is a smart contract loaded into the network and a client (e.g. the user’s browser) that interacts with this contract. In Cardano, there is a client, a backend application and code with data (smart contarct) stored in the blockchain.
🔴 The backend application in Cardano, can be created using the Plutus Framework, the official Cardano framework. It will allow us to easily program a backend application framework that will allow interaction with the client and give it the ability to construct data and contracts written to the blockchain.
🔴 In Cardano, the smart contract as part of the so-called on-chain code processed by the blockchain nodes is very small. This distinguishes Cardano from other blockchains. The on-chain code is a simple condition that, when provided in a transaction: the input data (EUTXO representing the data on the blockchain) and the unblocking data of the input EUTXO, is supposed to decide whether the input data can actually be unblocked. In Cardano, the on-chain code is called ‘validator script’, the EUTXO input data is called ‘datum’ and the unlock data is ‘reedemer’. If the validator script checks that the reedemer matches the datum, then the processing of the ‘smart contract’ is correct and the new data can be written to the blockchain (as a result of the processing of the smart contract).
🔴 In Cardano, an important part of the web3 application is the backend/server part, run by the web3 solution provider. Although it does not have the possibility to interfere with the correctness of the processing, it is needed and must work for the whole to function. Unlike in Ethereum… There, all that is needed is the user and the blockchain. In a working web3 Cardano solution – the backend part is also needed.
🔴 Is the programming model in Cardano because of the backend part…. centralised? I will touch on this topic in my next post.