Smart contracts are part of web3 and are small programs that run autonomously when predetermined conditions are met. If you are new to web3, I would suggest checking out this blogpost highlighting some of the common terms. These programs are generally short (less than 500 lines of code) and are stored entirely on a public distributed ledger like a blockchain. Anyone can view the source code of the contract and verify it does what it's supposed to do. Smart contracts, once deployed are immutable and unable to be changed.
Smart Contracts primarily written in a typed programing language called Solidity. Solidity files have the .sol extension. An example can be viewed here. Solidity developers are in very high demand and I recommend learning about the limitless opportunities that smart contracts allow.
Smart contracts are an important piece of decentralized applications which we will talk a little more about in the next section.
The autonomous nature of smart contracts has allowed innovators to build entirely self sufficient applications on distributed ledgers. Some of the most notable applications that have helped define decentralized finance have been built using smart contracts. Notable Example are decentralized exchanges (like uniswap, dy/dx, and sushiswap), and marketplaces like opensea.
An advantage of these programs, is that you can verify they are what they are and do what they claim they are doing. This allows for a permission-less autonomous ecosystem between untrusted and anonymous stakeholders.
When writing smart contracts, functions can be defined as public or private. Public functions can be called by any permission-less party, while private functions can only be called by the smart contract itself. This specifies who can call these functions. It is also possible to set conditional criteria on these permissions. For example, some NFT projects will allow their users access to an exclusive airdrop if the users' wallet has one of the existing NFTs. There are many opportunities to customize the scope logic.
Composability is the ability to integrate and work with other systems. Since smart contracts deployed on a public ledger are public, they can be accessed and interacted with by other smart contracts. This gives fruit to an ecosystem of contracts that can interact with each other.
Using a decentralized public ledger requires transaction fees to pay for the network operation. This is also true regarding smart contracts. When you deploy a smart contract to a network you have to pay a one time fee to the network to compensate the allocation of the program on the ledger. This is the primary reason why these contracts are generally short, the larger your program the more expensive it is to deploy.
The other cost is to the users who interact or run the contract. These are similar to traditional network fees, and they reward the node validators for running the programs in the Ethereum Virtual Machine. There is currently criticism around the large transaction fees on the Ethereum network.
The rate of innovation in this space is lightning fast. While smart contracts were originally only supported on the Ethereum network, now there are many networks taking things further. One of these networks is Hedera Hashgraph who publicly announced their Smart Contracts 2.0 Service which will allow their native network advantages to be utilized with smart contracts. This means that they will be able to support significantly more transactions per second than smart contracts on other networks for a fraction of the cost. The supported scalability of these services is very exciting. More information on the new smart contracts can be found here.