Blockchain
What is a smart contract?
October 2, 2023
TLDR

Smart contracts are blockchain-based automated computer programs that enforce their coded rules. Using “if this, then that” logic, smart contracts power NFTs and dApps on the blockchain. Buying and selling NFTs using OpenSea is powered by the smart contract protocol, Seaport.

What is a smart contract?

Historically, banks and institutions provided a key function in our world’s many transactions. From money transfers to legal deeds, the ability of the parties to fulfill their respective part of the agreed-upon transaction has been assessed by each bank or institution’s own set of rules (whether the rules were fully public or not). And records of transactions or agreements of many kinds have typically been stored in centralized databases, where they are accessible only to certain parties.

But web3 and crypto are introducing a new way. What if the success or failure of transactions could be assessed through pre-programmed code based on the parameters of the parties’ agreed-upon transaction including details like how much items cost, where payment is sent and who authorizes the transaction?

Welcome to the future, where transparent, decentralized code can help perform some of the duties that humans have historically completed with more centralized guidelines and record keeping. This kind of programmability is possible through the use of smart contracts, automated computer programs that run on blockchains. 

Smart contracts are a core part of the on-chain code that powers non-fungible tokens (NFTs), decentralized applications (dApps), and decentralized finance (DeFi) protocols. The term “smart contract” dates back two decades. Nick Szabo, a cryptographer and computer scientist, coined the term as a graduate student at the University of Washington. He wrote that smart contracts would be defined by “a set of promises, specified in digital form, including protocols within which the parties perform on these promises.” In practice, those promises, or rules, are what enable what we see in NFTs’ functionality and more.

For instance, a smart contract helps track an NFT’s ownership records, making it possible to verify and easily transfer the digital item from one owner to the next without the need for a third-party intermediary. 

Smart contracts exist on the blockchain, a digitally distributed ledger that records transactions and information across a decentralized network. Most blockchains are verified by many nodes (read: computers), which is why you’ll hear them described as “decentralized.” Different blockchains may verify their transactions using different methods but ultimately operate similarly. 

How do smart contracts work? 

Smart contracts follow anif this, then that” logic. Szabo famously compared smart contracts to a vending machine. 

As with a vending machine, humans program logic into the smart contract so it will trigger a desired function when certain parameters are met. For example, a vending machine dispenses the customer’s selected item once the right buttons are pressed and the appropriate amount of money is fed into the machine. A similar thing occurs with a smart contract, which will only produce a certain output based on its coded rules when all conditions and contingencies are met. 

It’s also important to note that certain interactions with smart contracts require gas fees. 

In web3, the term “gas fee” refers to the payment needed to execute transactions on the blockchain. These payments compensate the validators who keep the blockchain functioning. This validation helps ensure the blockchain has a permanent, immutable record. 

Blockchains that support smart contracts include Ethereum, Base, and Avalanche. 

What are the advantages of smart contracts?

Publicly available and secure 

Smart contracts are recorded on the blockchain and, therefore, are publicly available to anyone who can access the blockchain. They also inherit the blockchain’s decentralized, open nature, which means they can be easily authenticated. For instance, anyone can review the blockchain records (like NFT transactions) related to a smart contract. On OpenSea you can do this by going to an NFT’s page, clicking “Details” and clicking the hyperlinked “Contract Address,” which will take you to etherscan.io, a third-party blockchain explorer tool. 

Speed and efficiency

A smart contract is an automated computer program (code) that lives on the blockchain. Smart contracts typically have a specific purpose, so they can be programmed for efficiency and transactions which relate to smart contracts (like those involving NFTs) can be processed quickly on the blockchain. 

Immutable 

A smart contract's own history and those of related NFTs cannot be erased or deleted. Any updates made on the blockchain (whether to code like smart contracts or NFT ownership records), occur only after independent validators reach consensus on the updates to the blockchain to verify the change.

What are smart contracts used for? 

Smart contracts help power NFTs and dApps. 

NFTs

Non-fungible tokens are unique, digital items with blockchain-based records of ownership. They’re bought and sold with cryptocurrency. Examples of NFTs include digital art, collectibles, virtual reality items, crypto domain names, ownership records for physical items, and more. 

dApps

dApps is a shortened form of “decentralized applications.” Unlike the apps utilized by web 2.0 that are owned by a single entity, dApps utilize blockchain technology, though they don’t necessarily need to be decentralized themselves. dApps can be operated via peer-to-peer network on the blockchain, or they can operate using traditional hierarchical structures, but what makes them dApps is their utilization of decentralized protocols.

How are NFTs and smart contracts related? 

NFTs use smart contracts as their foundation. Smart contracts help track ownership information and allow for seamless, instant transactions. Seaport, a smart contract protocol, provides a set of rules that allows validators to process transactions based on the individuals’ signed instructions sent to the blockchain via their third-party wallets.

🧠 Q&A

Are there other ways you can use smart contracts beyond art or music NFTs?

Yes, there are several other wrapped tokens other than WETH. Some examples include WMATIC (wrapped Matic), WBTC (wrapped Bitcoin), WDOT (wrapped Polkadot), and WLTC (wrapped Litecoin). Not every token can be used on OpenSea. Learn More.

How are smart contracts and virtual land related?

Smart contracts help track ownership of the “virtual deeds” associated with virtual land. You can learn more about virtual land and the metaverse by reading our deep dives on them in the Learn Center.

How do I properly vet an NFT before buying it?

Web3 technology is still new and constantly evolving, so while no single action guarantees protection, there are best practices that can help. The best rule of thumb is that if something looks too good to be true, it probably is. Never share your wallet’s seed phrase, be careful when taking actions using your wallet, and make sure to thoroughly evaluate NFTs before buying.

OpenSea also has an icon visible via a blue checkmark badge on a collection or account. A blue checkmark badge on an account means that account has been verified. A blue checkmark badge on a collection means the collection belongs to a verified account and has significant interest or sales. (OpenSea does not endorse verified accounts or badged collections, and OpenSea makes no representations regarding the NFTs in a verified account or badged collection.)

OpenSea makes no representations or guarantees regarding the collections highlighted in this article.  Users must do their own research and use their own judgment before buying any NFT, including those included in the collections highlighted in this article.  The descriptions of the collections highlighted in this article were adapted from descriptions provided by the NFT creators, not OpenSea.