Tezos for Newbies 2: Smart Contracts, dApps, and NFTs
We continue explaining the decentralized world. Today we'll talk about how smart contracts and decentralized applications work on Tezos and other blockchains.
We break down the terms and explain how smart contracts and dApps work. Don’t forget to check out the first part of the knowledge base about blockchain, transactions, and tokens!
What Are Smart Contracts and How Do They Work?
What is a smart contract? It is a program stored and running on a blockchain. It consists of executable code (the instructions for operation) and storage (a proprietary database inside the blockchain.) Each contract also has an address at which it is called by users and other contracts.
What is a blockchain virtual machine? It is the execution environment for smart contracts on the blockchain. The virtual machine runs inside blockchain nodes.
What is a smart contract call? It is a call to a function (entry point) in its code. Often in a call, you need to transfer parameters. For example, when sending tokens, the parameters would be the number of tokens, the sender’s address, and the recipient’s address.
How do smart contracts work? When a user calls a contract entry point, it sequentially executes the code with the parameters received. If it completes the execution, it records the result in a repository. For example, when it sends tokens, it will change the balances of the recipient and the sender.
Learn more from “How do smart contracts work in general?”
Where are smart contracts used? In almost all blockchain activities, except for native token transactions and some transactions like baking, delegating, publishing a protocol update proposal, and voting for them.
Why do I have to pay transaction fees to use smart contracts? Smart contracts are executed inside a virtual machine that runs on blockchain nodes. Accordingly, when a contract is called, the user pays for the time of the node as well as the cost of overwriting the data in the storage. The more complex the contract code and the more data that needs to be written, the more expensive it is to execute.
Why are smart contracts better than centralized programs?
- they benefit from the advantages of blockchain: decentralized data storage, resistance to censorship, and no intermediaries;
- their code is public: an experienced developer can check it and verify its honesty;
- the entire transaction history of smart contracts is stored on the blockchain.
How are smart contracts inferior to centralized programs?
- you have to pay to record data on a blockchain, and smart contracts cannot be used for free;
- the blockchain has a limit for complex transactions, and nodes will not process a smart contract call that exceeds the limit. For example, when sending tokens to multiple addresses in a single transaction (transaction batching), you can specify no more than 500 addresses or the node will not be able to execute the transaction.
What Are Blockchain Apps and How Do They Work?
What is a blockchain application or dApp? These are desktop, mobile, or web applications that use smart contracts and blockchain.
Blockchain applications can also be described as a graphical interface for dealing with smart contracts. For example, to exchange tokens on a decentralized exchange, a user can go to its website and click a few buttons, or call up the desired smart contract and pass the exchange parameters to it.
A blockchain wallet is also a blockchain app.
What are DeFi applications? They are decentralized applications that focus on financial transactions:
- DEXs are decentralized exchanges for exchanging tokens. Learn more in the SpicySwap DEX review and the QuipuSwap piece;
- Farms, Staking and Passive Income ones are applications for long-term investments. Read about liquidity banking and the DeFi dictionary;
- Lending protocols are for borrowing and lending. On Tezos, there is Yupana and flash loans;
- Synthetic assets and algorithmic stablecoins are for issuing tokens whose price is tied to other crypto like BTC, fiat currencies, precious metals, or other assets. Read more about youves, Kolibri Finance and ctez;
- Prediction markets and derivatives are essentially for betting on the outcome of certain events;
- DAOs (decentralized autonomous organizations) are protocols for voting, and optionally for automatic execution of decisions like allocating funds from the app’s treasury. Learn more about Tezos’ most active DAOs;
- Oracles are applications that pull data from the internet or other sources and deliver it to other blockchain applications. For example, oracles can supply gold prices for a synthetic asset platform or soccer game results for a prediction marketplace.
What is NFT? NFT stands for “non-fungible token,” a non-interchangeable token with a unique identifier.
NFT is most often used to tokenize art: a user issues a non-fungible token with an image, music, text, or other digital object attached to it. Pegging something to a token is called tokenization.
NFTs can be created by writing a smart contract to issue unique tokens, or you can use the appropriate application called the NFT marketplace. You can also trade NFTs there.
More details — in our workshop about NFT.
What is GameFi? GameFi refers to games that use blockchain and allow players to earn. For example, to mine and sell in-game resources or play honest casinos. Tezos has some interesting games: here’s a selection of games and an in-depth review of Emergents.
GameFi became possible by issuing game resources as regular tokens or NFTs. These can be traded and exchanged with other players directly or on decentralized exchanges.
What other blockchain applications are there? Smart contracts can be used to implement any application that would benefit from a decentralized database, log in through a blockchain wallet, or payments in tokens:
- Decentralized social networks: the user logs in with a wallet, messages are stored in encrypted form and cannot be deleted, users can send tokens to each other or collect donations. Tezos already has its first instance of those, a decentralized chat room called Quilt;
- Business applications: purchase receipts for goods in the form of NFTs, tokens instead of points, or token staking to get discounts on future purchases;
- Production accounting: each product item gets assigned an NFT, and the system records all data about its movement on the blockchain;
- Renting without intermediaries: the user deposits tokens to access a rented house or car, and the contract regularly withdraws a fee from the deposit.
Subscribe and never miss updates from the world of Tezos: