What Is a Smart Contract?

A smart contract is a program stored on a blockchain that runs automatically when predefined conditions are met. It lets token transfers, swaps, lending and NFTs work without an intermediary.

On this page 6
  1. How do smart contracts work?
  2. What are smart contracts used for?
  3. Are smart contracts safe?
  4. What should you check before using one?
  5. Frequently asked questions
  6. Source

A smart contract is a program stored on a blockchain that runs automatically when predefined conditions are met. The classic analogy is a vending machine: put in the right amount, make your selection, and the product comes out without a cashier. Token transfers, decentralized exchange swaps, lending protocols and NFTs all run on smart contracts.

How do smart contracts work?

Computer scientist Nick Szabo described the idea in the 1990s, but it only took off at scale after Ethereum launched in 2015. A smart contract’s life cycle looks like this:

  1. A developer writes the code in a language such as Solidity and compiles it.
  2. The code is deployed to the blockchain in a transaction and receives a permanent address.
  3. Users or other contracts call its functions by sending transactions to that address.
  4. Every node runs the code under the same rules (the EVM on Ethereum) and reaches the same result.

Each interaction costs a gas fee to pay for the computation. If the conditions aren’t met, the transaction fails, but you still pay for the computation used up to that point.

The word “smart” doesn’t mean the program thinks for itself; it simply executes the rules it was given. Nor does “contract” mean the code is automatically a legally binding agreement in any given country.

What are smart contracts used for?

  • Tokens: USDT, USDC and UNI are all contracts written to the ERC-20 standard.
  • DeFi: decentralized exchanges like Uniswap and lending protocols like Aave run entirely on contracts.
  • NFTs: ownership of digital collectibles is tracked through standards such as ERC-721.
  • DAOs: community votes and treasury management are carried out in code.

Beyond Ethereum, networks such as Solana, BNB Chain, Avalanche and Cardano also support smart contracts.

How do smart contracts get outside data?

A contract can’t see anything off-chain on its own, whether that’s the dollar price of a coin or the result of a football match. That information is brought on-chain by services called oracles. Lending protocols, for instance, value collateral using oracle prices, so a faulty or manipulated feed can cause losses even when the contract code itself is flawless.

Are smart contracts safe?

Code deployed to a blockchain usually can’t be changed, which also means bugs are hard to fix. In the 2016 attack on The DAO, a flaw in the contract was exploited to drain a large amount of ETH; the decision to reverse it split the network into Ethereum and Ethereum Classic. Since then, coding errors, manipulated price feeds and compromised admin keys have caused major losses across DeFi.

Open-source code and independent audits reduce risk but don’t eliminate it. Some contracts are deliberately “upgradeable,” meaning the team behind them can change how they work later.

What should you check before using one?

  • Verify the contract address through the project’s official channels; fake tokens with identical names are common.
  • Read your wallet’s approval screen to see which contract you’re granting a spending allowance to, and for how much.
  • Disconnecting your wallet from a site doesn’t revoke on-chain approvals, so cancel the ones you no longer need.

Frequently asked questions

What language are smart contracts written in?

Solidity is the most common language on Ethereum and EVM chains, with Vyper as an alternative. Solana programs are usually written in Rust.

Can a smart contract be changed?

A standard contract’s code can’t be modified after deployment. With upgradeable designs, whoever holds the admin rights can change the contract’s behavior.

Source

Read next