dApp basics · Explainer
What Is a Smart Contract? How They Work, Uses and Risks
A smart contract is a program that lives on a blockchain and runs exactly as written when its conditions are met. This guide explains how smart contracts work, what they power in DeFi, and how to judge their risks.
By the DappsAtlas editorial team · Updated

What is a smart contract?
A smart contract is a program stored on a blockchain that executes automatically when predefined conditions are met. It has its own address, can hold data and funds, and exposes functions that users or other contracts can call. Once a call is made, the network runs the code and records the result.
The name is slightly misleading. A smart contract is not artificial intelligence, and it is not automatically a legal contract. It is better understood as self-executing software with rules fixed in advance.
Computer scientist Nick Szabo introduced the term in the 1990s and compared the idea to a vending machine: put in the right input and the machine delivers the output without a clerk. Bitcoin offered only limited scripting, and Ethereum, launched in 2015, made general-purpose smart contracts mainstream. Many other chains now support them.
Smart contracts tend to share these traits:
- Self-executing: no person has to approve each step once the rules are set.
- Deterministic: every node running the same code with the same input must reach the same result.
- Transparent: the bytecode is public, and the source code is often published and verified.
- Composable: contracts can call one another, so protocols can be built from other protocols.
- Usually hard to change: deployed code is normally fixed unless it was designed to be upgradeable.
These traits explain both the appeal and the risk. Rules enforced by code remove the need to trust a middleman, but they also mean mistakes in the code can be costly.
How does a smart contract work?
A smart contract goes through a short lifecycle, and understanding it makes most dApp behaviour easier to follow.
- Writing: developers write the logic in a language such as Solidity or Vyper for Ethereum-style chains, or Rust for Solana.
- Compiling: the source code is turned into bytecode the blockchain's virtual machine can run.
- Deploying: the bytecode is sent in a transaction. The network assigns the contract an address, and from then on it exists on-chain.
- Calling: a user or another contract sends a transaction to that address, naming a function and supplying inputs.
- Executing: validators run the code. Every node checks the result, and the contract's stored state is updated if the call succeeds.
- Reverting: if a condition fails or gas runs out, the whole call is cancelled and state changes are undone, though the gas spent is not refunded.
Two kinds of interaction are worth separating. A read call only looks at stored data, for example a balance, and costs nothing. A write call changes state, needs a signed transaction from a wallet, and costs a network fee known as gas.
Contracts cannot fetch web data by themselves, because every node must be able to reproduce the result. When a contract needs outside information, such as an asset price, it reads from an oracle, a service that posts that data on-chain. The oracle then becomes part of the system's trust and risk profile.
A simple example: how an escrow contract behaves
A classic illustration is an escrow contract for a sale between two people who do not know each other.
- The buyer and seller agree the terms: an amount of a token, a deadline and a condition for release.
- The buyer sends the payment to the contract address. The funds are now held by code, not by either person.
- The seller delivers the goods or service.
- When the agreed condition is met, for example the buyer confirms receipt or a trusted data source reports delivery, the contract releases the funds to the seller.
- If the deadline passes without the condition being met, the contract returns the funds to the buyer.
No bank or escrow agent has to approve the transfer. The logic was written down before any money moved, and neither party can change it midway.
The example also shows the limits. The contract can only verify things the blockchain can see. It cannot tell whether a parcel arrived unless someone, or some oracle, reports it. If the release condition depends on a person clicking a button, a dispute may need a human arbiter built into the design.
Most real DeFi protocols are more elaborate versions of the same pattern: deposit assets, follow fixed rules, withdraw according to those rules. Lending markets, staking pools and token vesting schedules all work this way, with more inputs and more moving parts.
Where do smart contracts run, and in what languages?
Smart contracts run on blockchains that include a programmable execution environment. The details differ, but the idea is the same.
| Platform family | Typical language | Notes |
|---|---|---|
| Ethereum and EVM-compatible chains, including most layer-2 networks | Solidity, Vyper | The largest ecosystem. Code is compiled to bytecode for the Ethereum Virtual Machine. |
| Solana | Rust | Contracts are called programs, and data is stored in separate accounts. |
| Aptos and Sui | Move | A resource-oriented language designed to make asset handling safer. |
| Cardano | Plutus and related tools | Uses a different accounting model from Ethereum. |
| Bitcoin | Bitcoin Script | Deliberately limited, so complex contracts are rare on the base layer. |
Because many chains share the EVM, the same contract code can often be deployed on several networks. A protocol may then run separate copies on each chain, each with its own address, balances and risks. That is why a dApp such as Compound V3 can operate on Ethereum and several other chains while behaving as an independent deployment on each.
Solana-native products such as Kamino Lend and Lulo use Solana programs, while Cardano tooling such as Clarity is built around that ecosystem's own contract model.
When you use a dApp, check which network your wallet is connected to. The same token name on a different chain is a different asset with a different contract address, and sending funds to the wrong network can mean they are lost or hard to recover.
What are smart contracts used for?
Smart contracts are the foundation of decentralized finance and much of the wider crypto economy. Common uses include:
- Tokens: fungible tokens and NFTs are contracts that track who owns what and enforce transfer rules.
- Lending and borrowing: users supply assets to a pool and borrow against collateral. Compound V3 and Kamino Lend are examples, and the contracts handle interest accrual and liquidations.
- Liquid staking: contracts take deposited assets, stake them and issue a receipt token. Lido issues stETH, and Rocket Pool issues rETH.
- Stablecoins backed by collateral: crvUSD is minted against deposited crypto, with contract rules controlling collateral ratios and liquidations.
- Decentralized exchanges: automated market makers hold token pools and set prices by formula.
- Yield vaults and aggregators: contracts move deposits between strategies. Convex Finance and vfat.io operate in this area, and vfat.io is built on the Sickle smart contract wallet.
- Token locks and vesting: Team Finance lets projects lock liquidity and team tokens under fixed release rules.
- Tokenized funds: Enzyme Finance provides infrastructure for on-chain fund strategies.
- Governance: DAOs use contracts for proposals, voting and treasuries.
The common thread is that the contract replaces a manual process, such as an administrator approving withdrawals, with rules anyone can inspect. That does not make every product safe or well designed. The rules may be badly written, or controlled by a small group that can change them. Reading what a contract does matters as much as knowing that it exists.
How do smart contracts differ from traditional contracts?
A smart contract and a traditional contract both set out obligations, but they work in different ways.
| Feature | Traditional contract | Smart contract |
|---|---|---|
| Form | Written language, often interpreted by lawyers | Code that runs on a blockchain |
| Enforcement | Courts, arbitration or voluntary compliance | Automatic execution by the network |
| Flexibility | Terms can be negotiated or amended by agreement | Fixed unless the code allows upgrades |
| Ambiguity | Common, and resolved by interpretation | Code does exactly what it says, including its bugs |
| Speed and cost | Slower, with professional fees | Fast, with network fees |
| Access to real-world facts | Parties and courts can judge them | Needs oracles or trusted reporters |
| Reversal | Possible by agreement or court order | Usually irreversible once confirmed |
The phrase often used in crypto is that code is law. In practice, that is a design aim and not a legal fact. A smart contract may carry out a transfer that a court would later consider wrongful, and the on-chain result may be impossible to undo.
Some agreements pair the two forms. A legal contract can refer to an on-chain mechanism for payment, while the written terms cover what code cannot, such as disputes, identity and off-chain delivery. If money or rights outside crypto depend on the outcome, legal advice in your own jurisdiction is a sensible step.
What are the risks of smart contracts?
Smart contracts remove some forms of counterparty risk but add technical risks of their own. The main ones are:
- Code bugs: a flaw can let an attacker drain funds. Reentrancy, where a contract is called again before its first run finishes, was the weakness exploited in the 2016 attack on The DAO, an early Ethereum project.
- Oracle failures: if a price feed is manipulated or wrong, lending and liquidation logic can act on bad data.
- Admin keys and upgradeability: many contracts can be changed by a multisig wallet or governance vote. That can fix problems, but it also means a small group may hold significant power.
- Economic design flaws: the code can work as written while the incentives fail under stress, causing bad debt or a stablecoin losing its peg.
- Dependency risk: composable protocols inherit the risks of everything they connect to, so a failure in one contract can spread.
- Phishing and malicious contracts: fake sites ask users to sign approvals that give a contract access to their tokens.
- Irreversibility: a mistaken or malicious transaction usually cannot be reversed, and there is no support desk that can undo it.
Audits help by having independent reviewers examine the code, but an audit is a snapshot, not a guarantee. Protocols that rely on risk specialists, such as vaults curated by Gauntlet, add a layer of parameter-setting and monitoring, though that is still not protection against every failure.
Assume any smart contract could fail, and only commit amounts you could afford to lose.
How can you check a smart contract before using it?
Before connecting a wallet to a contract-based product, a few checks cut risk meaningfully. These are defensive habits, not guarantees.
- Confirm the real address. Use the project's official documentation to find contract addresses and avoid copies shared in messages or ads.
- Check a block explorer. Look for a verified source-code badge, the contract's age and its transaction history. Unverified code is a warning sign.
- Find who controls it. Identify whether it is upgradeable, who holds the admin keys, whether a multisig or timelock is used, and whether the owner can pause or change key parameters.
- Read the audit reports. Check who audited it, what was found, and whether the issues were fixed. Note that code changed after an audit is not covered by it.
- Review what you sign. Wallet prompts for token approvals show which contract can spend your tokens and how much. Avoid unlimited approvals where a limited amount works.
- Revoke old approvals. Approval-management tools let you cancel permissions you no longer need.
- Start small. Test with a small amount first, including the withdrawal step.
- Use a separate wallet. Keep long-term holdings apart from the wallet used to try new dApps.
Time-sensitive details, such as total value locked, current audit status, recent incidents and governance changes, change often. Check them directly on the protocol's documentation, a block explorer and independent DeFi data dashboards at the time you decide, not from an article.
How are smart contracts different from using a centralized exchange?
Not everything in crypto runs on smart contracts. Centralized exchanges such as OKX, Bitvavo, Bitget, Gate and others operate differently from on-chain protocols.
On a centralized exchange, you deposit funds to an address the company controls. Your balance is an entry in the company's internal database, and trades are matched off-chain on its servers. Withdrawals are processed under the exchange's rules, and you rely on the company for custody, solvency and compliance. In many regions, they also require identity verification.
On a smart-contract protocol, you keep your assets in your own wallet until you choose to interact. When you do, the contract holds or moves funds according to public code, and you do not need the operator's approval to withdraw, provided the code allows it. You are exposed to code risk instead of company risk.
| Aspect | Centralized exchange | Smart-contract dApp |
|---|---|---|
| Custody | The company holds assets | The contract or your wallet holds assets |
| Rules | Company policy and terms | Code, plus any admin powers |
| Account recovery | Possible through support | Not possible without your keys |
| Main risks | Insolvency, freezes, hacks of the company | Bugs, oracle failures, malicious approvals |
Some exchanges also offer Web3 wallets or earn products that touch on-chain protocols. When you use those features, read where your funds are held and which risks apply to each product.
Where do smart contracts show up in crypto gambling?
Crypto casinos and betting sites use smart contracts in different ways. Some on-chain games place bets, calculate results and pay out through contract code, with randomness supplied by a verifiable on-chain method or an oracle. Others are conventional operators that only accept crypto deposits and run their games on private servers, which involves no smart contract at all.
The distinction matters because the trust model is different. An on-chain game lets you inspect the payout rules and check that results can be verified. An off-chain casino asks you to trust the operator's software, fairness claims and licensing. Even where a contract is verifiable, a poor design, weak randomness or admin controls can still work against players.
Before using any gambling product:
- Confirm you are 18 or older, or the higher legal age where you live.
- Check local laws. Online gambling is restricted or banned in many places, and the rules differ by country and region. It is your responsibility to follow them.
- Do not try to bypass geo-restrictions, age checks or identity verification. Operators apply them for legal reasons, and getting around them can void accounts and winnings.
- Set limits. Decide a loss limit in advance and treat any stake as money you can afford to lose.
- Check where help is available. If gambling stops being fun, use self-exclusion tools and local support services.
A smart contract may make rules visible, but it does not make gambling safe or lower the odds against the player.
How can a beginner start with smart contracts safely?
You do not need to write code to understand or use smart contracts, but a gradual approach helps.
- Learn the vocabulary. Terms such as wallet, address, gas, approval, oracle and multisig come up constantly, and knowing them makes wallet prompts less confusing.
- Pick a simple use case. Sending a token, or supplying an asset to a large, established lending market such as Compound V3, shows the core pattern without the complexity of leveraged or multi-step strategies.
- Read the documentation. Official docs describe what each function does, what the fees are, and what can go wrong. They also list the correct contract addresses.
- Look at your own transactions. After a transaction confirms, open it in a block explorer and see which contract you called, what it did and what it cost. This habit builds understanding quickly.
- Manage permissions. Keep track of the approvals you have given and revoke those you no longer use.
- Learn to read, not only to use. Developers can start with Solidity tutorials and a test network, where mistakes cost nothing. Non-developers can still read verified code summaries and audit reports.
For anything time-sensitive, such as a protocol's current security status, supported networks, fees or recent incidents, go to the project's official channels, a block explorer and independent data dashboards. Smart contracts change over time through upgrades and governance, so what was true when an article was written may no longer hold.
Frequently asked questions
Is a smart contract a legally binding contract?
Usually not on their own. A smart contract is code that enforces its own rules, while a legal contract is an agreement recognised by law. Some jurisdictions have rules that recognise electronic or code-based agreements, so check local law if a real legal agreement is involved.
Can a smart contract be changed after it is deployed?
Not by default. Once deployed, the code at an address generally cannot be edited. Many projects use upgradeable designs, such as proxy contracts, where an admin key or governance vote can swap the logic. Whether a contract can change, and who controls that power, is one of the first things to check.
Do I need to know how to code to use a smart contract?
No. Using a dApp means signing transactions from a wallet, and the interface calls the contract for you. Writing contracts requires a language such as Solidity, Vyper, Rust or Move, but using them does not. Understanding what you are signing is still important.
Are smart contracts safe?
No. A contract that has been audited or has run for years can still contain bugs, depend on a faulty price feed, or be controlled by an admin key. Audits reduce risk but do not remove it. Transactions are normally irreversible, so size positions with that in mind.
What is gas and why do smart contracts need it?
Gas is the fee paid to the network to execute a transaction. More complex contract calls use more computation and usually cost more. Fee levels change constantly, so check a gas tracker or your wallet's estimate before confirming.
Can smart contracts access data from the internet?
Not directly. Contracts can only read data on their own chain. To use outside information such as asset prices, they rely on oracles, which are services that publish external data on-chain. The reliability of the oracle becomes part of the contract's risk.
Mentioned in this guide
dApps in this guide
Compound V3 is a lending protocol on Ethereum and nine other chains where users supply a base asset for yield or borrow it against collateral.
Lido is a liquid staking protocol where users stake ETH and receive stETH, a reward-earning token usable across DeFi, governed by LDO holders.
Rocket Pool is a decentralised Ethereum liquid staking protocol offering rETH for stakers and 16 ETH validators for node operators.
Team Finance is a non-custodial platform where token projects create tokens, lock liquidity and team tokens, set up vesting, run staking pools and airdrops.
Enzyme Finance is infrastructure for issuing and managing tokenized funds and on-chain strategies, aimed at asset managers, institutions and DeFi builders.
crvUSD is Curve Finance's overcollateralized, USD-pegged CDP stablecoin on Ethereum, minted against crypto collateral by DeFi borrowers.
Kamino Lend is a peer-to-pool lending market on Solana where users earn interest on deposits or borrow against crypto collateral.
Gauntlet is a DeFi risk manager that curates non-custodial yield vaults for fintechs, exchanges, wallets and asset managers.
Bitget is a centralized exchange for crypto spot and futures that also offers tokenized stocks, commodities and forex in one account, for active traders.
Keep reading
Related guides
dApp basics · Explainer
What Are dApps? How Decentralized Apps Work in 2026
A dApp is an application whose core rules run as smart contracts on a blockchain, and you use it through a crypto wallet instead of an account. This guide covers how dApps work, the main types, what they cost and how to judge the risks.
DeFi · Explainer
Jade Protocol and JADE Token Explained: A 2026 Guide
Jade Protocol is a DeFi project whose token trades under the ticker JADE. This guide explains how to identify the real token, how projects of this type usually work, and how to check every time-sensitive detail yourself.
Blockchain · Chain guide
Casper Network Explained: A Blockchain Built for Enterprise
Casper Network is a proof-of-stake layer-1 that has aimed at enterprises and developers since its 2021 mainnet launch. This guide covers how it works, what CSPR does, how staking works and what to weigh before using it.
DeFi · Explainer
What Is DeFi? A Complete Guide to Decentralized Finance (2026)
DeFi replaces banks and brokers with smart contracts that anyone can use from a wallet. This guide covers how exchanges, lending, stablecoins and staking work, what can go wrong, and how to research a protocol before using it.
dApp basics · Explainer
What Is a TRON dApp? How They Work, Costs and Safety (2026)
A TRON dApp is an application whose key logic runs as smart contracts on the TRON blockchain. This guide covers how they work, what they cost to use, the main types, and how to check one before connecting a wallet.
dApp basics · Explainer
What Is a Crypto Exchange Platform?
A crypto exchange platform lets you buy, sell, or swap digital assets. Learn how centralized and decentralized exchanges work, what they cost, and how to choose one.
dApp basics · Explainer
What Is a dApp Discovery Site and How Its Data Works (2026)
A dApp discovery and analytics site is an independent guide that tracks decentralized apps across blockchains and reports activity such as users, volume and transactions. This guide explains what these sites show, how to read their numbers, and where their data can mislead.
dApp basics · Explainer
DappLaunch Growth Announcement: What It Means for Web3 Projects
DappLaunch has announced a plan to help Web3 projects grow. This explainer covers what such announcements usually mean, what to check before engaging, and how to verify claims without relying on the headline.