Types of Smart Contracts: Their Kinds and How they Differ
Smart contracts are the backbone of blockchain games, NFT collections, and web3 apps; but what are their types and how do they differ?
Smart contracts are at the core of web3. They are pieces of code that live on the blockchain and work like vending machines: Give them an input and they do the rest — be it transferring funds, registering ownership, or anything else that pre-defined.
From simple token swaps and lending transactions to complex social media algorithms and DAO governance, smart contracts power every web3 app. With such a range of use cases, it’s natural that different types of smart contracts have emerged. In short, different types of smart contracts can enable different functionalities, and unlock new use cases.
Want to explore the different types and options you have for smart contract deployment? Sit tight! In this blog, we will explain everything a developer needs to know about the different types of smart contracts that you can build or use.
But before we dive into that, let’s do a quick recap of what smart contracts are.
What are smart contracts?
Smart contracts are pieces of code that reside on a blockchain, and they automatically execute predefined actions when certain conditions are met. This execution happens without the need for any human involvement. Also, smart contracts operate transparently with the actions immutably recorded on a blockchain.
The Origin of Smart Contracts
The history of smart contracts goes further back than you might expect. Nick Szabo coined the term "smart contract" in 1994. And in 1996, he delved into their potential applications. Years later his vision became reality, thanks to the launch of the Ethereum network.
Ethereum was the first blockchain to introduce smart contract functionality. To simplify the web3 development process, Ethereum introduced Solidity, a programming language for writing and implement smart contracts.
Technically, smart contracts are Ethereum accounts, or contract accounts to be specific. They are:
- an ‘account’ because they can hold, receive, and send ETH and other tokens.
- a ‘contract’ because once deployed they are not controlled by any user and they run as programmed.
While there are other blockchains that support smart contracts today, Ethereum was the first and, today, EVM chains are typically still most popular networks for decentralized apps leveraging smart contracts.
So, now you know what smart contracts are and where they came from, let’s dive into the types of smart contracts you may come across.
Types of smart contracts
Smart contracts have hugely versatile applications. From minting tokens with token contracts to making decisions through governance contracts, smart contracts can be tailored to meet specific needs. Let's take a look at what some of those specific needs can include:
Token contracts
Token smart contracts are used to create digital tokens. They specify attributes like token name, symbol, and supply, and implement functions for transferring tokens between accounts, approving transactions, and checking balances.
Token contracts usually fall into one of 2 categories: fungible or non-fungible tokens. There are such things as semi-fungible tokens, but these are typically grouped under the non-fungible category for their similar features.
Fungible tokens
Fungible tokens are often based on the ERC-20 token standard. These fungible tokens are exactly equal to any other token and no tokens possess special rights or behaviors.
ERC-20 tokens are versatile, and can be used to represent fiat currencies, such as with stablecoins, they can also act as governance tokens, granting members of decentralized communities voting rights, or provide the necessary tokens for staking. Most commonly, developers use ERC-20 tokens to deploy memecoins, since they are easy to set up and manage. However, the possibilities of ERC-20 tokens are really endless!
Non-fungible tokens
Non-fungible tokens (NFTs) are majorly based on the ERC-721 token standard on Ethereum. NFT smart contracts manage NFTs by ensuring the contract address, uint256, and tokenId are globally unique. The contract contains functions for minting, transferring, and inquiring about token ownership, and is pivotal in domains like digital art and collectibles.
CryptoPunks, a notable NFT collection of 10,000 unique characters, is powered by 250 lines of code. Amongst these, the game-changer functions are:
- nextPunkIndexToAssign: Gives a new, successive index to every Punk being minted.
- PunkBidEntered: Specifies the highest bid made for a CryptoPunk by a specific EOA.
- address onlySellTo: Defines that each NFT can be wholly sold only to one person i.e. one EOA.
For more,check out our full guide on NFT smart contracts and how they work. And if you're ready to start deploying, explore our NFT smart contract templates including features like allowlists, delayed reveals and more.
NFT and DeFi Marketplace smart contracts
Marketplace smart contracts facilitate the buying, selling, and trading of digital assets such as ERC-20 and ERC-721 tokens. As such, they play a crucial role in the DeFi and NFT space.
Marketplace smart contracts automate the trading process and ensure transparency and security of asset transfers. Typically on these platforms, smart contracts replace a central authority which enables true peer-to-peer trading.
Crypto and NFT marketplaces can include a range of functions. For example Uniswap's trading contracts include the following:
pairs: the smart contract responsible for the creation of automated market makers (AMMs).
pool: the smart contract that maintains the liquidity pools using the amount*Desired parameters.
But those aren't the only smart contracts at work for Uniswap. A single decentralized marketplace might rely on multiple smart contracts to execute different types of tasks.
Thus, building your own smart contracts to give your web3 marketplace these types of functionalities might be a challenge. But don't worry, with thirdweb’s marketplace smart contract templates, building a secure and performant app doesn't need to be complicated.
Airdrop contracts
The primary function of an airdrop smart contract is to transfer tokens to a list of recipient addresses. Although it sounds like a simple call to a .send() or .transfer() function, the contract has a lot more to offer.
Typically airdrop smart contracts let developers introduce an allowlist and eligibility criteria. They may also incorporate batch processing to handle transactions more efficiently and reduce gas fees.
For example, the Arbitrum airdrop, one of the most anticipated airdrops in history, contained the following functions and variables:
transferOwnership: A function that the owner (Arbitrum Foundation) calls to transfer the control of airdrop tokens to the smart contract. In this instance, the smart contract took control and airdropped over 1.1 billion $ARB tokens.
uint256 deadline: The variable that pre-defines the last date and time for eligible addresses to claim the airdrop.
Learn how to set up an airdrop with eligibility criteria here! And find the airdrop smart contract template here.
Smart wallets
Smart wallets are web3 wallets that use smart contracts for their transactional abilities. Instead of using an EOA to initiate a transaction and pay gas fees, smart wallets use UserOperation. It is a transaction-like structure that describes the execution terms and the necessary data for the verification.
This smart contract flexibility allows smart wallets to enjoy many benefits over regular (EOA) wallets. They can perform batch transactions, define transfer limits, assign guardians or recovery options, conduct multisig transactions, and much more.
Smart wallet contracts include key attributes like:
- isValidSignature(): **A function that validates messages signed by smart wallets similar to how EOAs sign messages with private keys.
- GuardianManager: A smart contract that manages the EOA-based guardians who help in the social recovery of the smart wallet.
- multiCall: A function to batch multiple transactions into a single transaction before posting on-chain.
Want to learn more? Check out our guide on how to deploy a smart wallet. And if you're ready to get deploying, check out the smart wallet contract template here!
DAO Smart Contracts
Decentralized Autonomous Organizations (DAOs) rely on smart contracts to automate governance and decision-making processes without centralized control. DAO smart contracts set the rules of the organization, manage the treasury, and facilitate transparent participation among members.
Voting Contracts
Voting contracts are essential for enabling decentralized decision-making within a DAO. They allow members to propose changes, vote on initiatives, and have a direct impact on the organization's direction. Key features of voting contracts include:
- Proposal Submission: Members can create proposals for new projects, protocol changes, or funding requests.
- Voting Mechanism: The contract defines how votes are cast and counted, which can be based on one vote per member or weighted by the number of governance tokens held.
- Quorum and Thresholds: Establishes the minimum number of votes required for a decision to be valid and the percentage needed for approval.
- Automatic Execution: Once a proposal passes, the contract can automatically execute the approved actions without further intervention.
Examples of DAOs utilizing voting contracts include MakerDAO and Compound Governance, where stakeholders actively participate in protocol governance.
Governance Token Contracts
Governance token contracts manage tokens that grant holders the right to participate in the DAO's governance processes. These tokens often serve as both a utility and an investment, aligning the interests of the members with the success of the organization. Key aspects include:
- Token Distribution: Defines how governance tokens are issued and allocated, whether through initial offerings, rewards, or vesting schedules.
- Voting Rights: Each token typically represents a vote, giving holders influence proportional to their stake in the DAO.
- Incentive Mechanisms: Encourages active participation by rewarding token holders who engage in voting and proposal activities.
- Stake-based Governance: Some DAOs require tokens to be staked or locked up to participate in governance, adding a layer of commitment.
An example is the UNI token used by Uniswap, which empowers holders to vote on protocol upgrades and fee structures.
Want to learn more about these contracts? Check out the full guide on DAO Smart contracts and how to deploy them.
How do different smart contracts work?
Different types of smart contracts work based on the specific logic and functions coded into them, tailored to their intended applications. While all smart contracts share the fundamental principle of executing predefined actions when conditions are met, the way they operate can vary significantly.
Token Contracts
Token contracts like ERC-20 and ERC-721 define how tokens are created, managed, and transferred. They include functions for minting new tokens, handling transfers between addresses, and updating balances. The standardized interfaces ensure compatibility across wallets and exchanges.
Marketplace Contracts
These contracts facilitate peer-to-peer trading by automating listing creation, bid management, and transaction settlement. They ensure that once a buyer meets the seller's conditions, the contract executes the trade, transferring ownership and funds securely.
Airdrop Contracts
Airdrop contracts automate the distribution of tokens to a large number of recipients. They handle eligibility verification, batch processing to optimize gas costs, and sometimes incorporate vesting schedules to release tokens over time rather than all at once.
Smart Wallets
Smart wallets use contracts to enhance security and functionality. They can require multiple signatures for transactions, enable recovery mechanisms without seed phrases, and allow users to set spending limits or automated routines.
DAO Smart Contracts
DAO contracts govern the rules of the organization. Voting contracts handle proposal submissions and the voting process, ensuring that all members have a say in decisions. Governance token contracts manage the distribution and staking of tokens that represent voting power.
In all cases, smart contracts are written in programming languages like Solidity and are deployed to the blockchain, where they operate transparently and immutably. Developers must carefully code and audit these contracts to prevent vulnerabilities, as they cannot be changed once deployed.
What types of smart contracts can I create?
Creating a smart contract usually requires writing it in a programming language that supports it (with the most popular being Solidity), testing and debugging it to ensure it’s secure, and deploying it to the blockchain.
But with thirdweb, you can skip all of this and deploy smart contracts easily — using a library of pre-built and audited smart contracts for any application, with the option to add custom extensions for advanced functionality on top.
Smart contracts & the future of the internet
Smart contracts that initially started as simple digital ‘if - then’ statements are today the backbone of the web3 space. Learning about them is necessary as we move towards this new iteration of the internet.
We hope this blog has helped you better understand what smart contracts are, how they work, and more importantly, their different types.
If you have any questions, join 40,000+ other builders in our Discord community. And if you want to deploy smart contracts in of your own, get started with thirdweb’s smart contracts library, web3 tools, and SDKs — they’re free!