Introduction to Decentralized Applications
What is a blockchain?
A blockchain is a digital, public ledger that records online transactions. Blockchain is the core technology for cryptocurrencies like bitcoin. A blockchain ensures the integrity of a cryptocurrency by encrypting, validating, and permanently recording transactions.
A blockchain is similar to a bank’s ledger, but open and accessible to everyone who utilizes the cryptocurrency is supports. Imagine two entities (eg banks) that need to update their own user account balances when there is a request to transfer money from one customer to another. They need to spend a tremendous (and costly) amount of time and effort for coordination, synchronization, messaging and checking to ensure that each transaction happens exactly as it should.
Typically, the money being transferred is held by the originator until it can be confirmed that it was received by the recipient. With the blockchain, a single ledger of transaction entries that both parties have access to can simplify the coordination and validation efforts because there is always a single version of records, not two disparate databases.
What is a smart contract?
A smart contract, also known as a cryptocontract , is a computer program that directly controls the transfer of digital currencies or assets between parties under certain conditions. A smart contract not only defines the rules and penalties related to an agreement in the same way that a traditional contract does, but it can also automatically enforce those obligations.
It does this by taking in information as input, assigning a value to that input through the rules set out in the contract and executing the actions required by those contractual clauses -- for example, determining whether an asset should go to one person or should be returned to the other person from whom the asset originated.
For example, imagine building a Kickstarter-like crowdfunding service on top of Ethereum. Someone could set up an Ethereum smart contract that would pool money to be sent to someone else. The smart contract could be written to say that when $100,000 of currency is added to the pool, it will all be sent to the recipient. Or, if the $100,000 threshold hasn’t been met within a month, all the currency will be sent back to the original holders of the currency. Of course, this would use Ether tokens instead of US dollars.
What is a dapp?
A decentralised application (dApp) is an application that runs on a decentralised network and uses its resources. The standard features of a dApp include:
Ethereum was the first blockchain for dApps. One of the success reasons of Ethereum was the technology called quasi-Turing Ethereum Virtual Machine (EVM). A Turing machine is a machine capable of simulating and running any computer algorithm. A piece of code for EVM is called a smart contract. Any smart contract or dApp code can be programmed for EVM and executed by the decentralised ethereum computer network.
The only restriction lies in the number of computations necessary to complete the algorithm of a smart contract. The currency that network nodes charge for computing smart contract’s code is called gas, which is limited. When a smart contract runs out of gas, it is terminated. This sets limitations to the resources a smart contract can use, comparing to the abstract Turing machine that has unlimited resources and can run infinite loops. That’s why EVM is called quasi-Turing.
The difference between an Ethereum dApp and a smart contract is that besides a smart contract, Ethereum dApp includes frontend application for user interaction. To run Ehtereum dApp in the web browser, the user has to install a browser extension that allows the browser to interact with the blockchain and manage user’s identity. Metamask is the most popular solution for desktop.