01

The misleading word "contract"

"Smart contract" suggests a legally binding agreement. In practice it is closer to a program running on a blockchain. When defined conditions are met, it moves assets or updates records exactly as its code says, and anyone can verify the result.

This guide explains how a smart contract stores state and runs functions, why execution costs gas, and what risks come from admin keys and upgradeable designs. It finishes with a checklist for interacting with a contract.

02

State and functions

Ethereum.org describes a smart contract as a collection of code (its functions) and data (its state) that lives at a specific address on the Ethereum blockchain. A token contract, for instance, stores how many tokens each address holds and changes those balances when its transfer function is called.

Functions come in two broad kinds. Those that only read state can be queried for free without a transaction; those that change state require a signed transaction and cost gas. A contract cannot do anything outside its rules, but if the rules contain a mistake, the mistake runs too.

03

A conditional example

In a hypothetical case, two people use an escrow contract for a second-hand sale. The buyer deposits 1 ETH; once the seller marks the item shipped and the buyer confirms receipt, the contract releases the ETH to the seller. If no confirmation arrives within 14 days, the contract can be designed to pay the seller automatically or refund the buyer, according to rules set in advance.

No intermediary is needed, but the contract cannot know whether the item really arrived. Who can press "confirm," and how disputes are handled, must all be written into the code beforehand. Real-world events the code cannot observe still depend on people or outside data.

04

Transactions and gas

Every state-changing execution costs gas in proportion to the computation it uses. Functions that perform complex calculations or write a lot of storage cost more, and if gas runs out midway, the transaction fails and the gas already spent is not refunded.

Gas is a cost but also a safety mechanism: it caps how much computation a transaction can consume, so an infinite loop cannot halt the network. That is why wallets show estimated gas and a maximum fee before you sign a contract call.

05

Permissions, upgrades, and outside dependencies

Deployed contract code is immutable by default, but many services use proxy patterns that allow upgrades. An address with upgrade rights can then change how the contract behaves, so who holds that right, and how it is exercised, matters. Ethereum.org's smart contract security documentation treats access control and upgrade management as major risk areas.

Main risk types in smart contract services
RiskWhat can go wrongWhat to check
Code bugsUnintended behavior, drained fundsAudit reports and whether findings were fixed
Admin keysOne address can move or freeze fundsMultisig control, scope of powers
UpgradeabilityBehavior can change after deploymentTimelocks and advance notice
OraclesBad prices trigger liquidations or tradesData sources and manipulation safeguards
Front endFake sites or tampered interfacesOfficial domain, contract address checked directly

Open-source code does not remove these risks. Publication makes verification possible; it does not guarantee safety.

06

Common misreadings

"It's on the blockchain, so it can't be hacked" is wrong. The blockchain's record is hard to alter, but if the contract code has a flaw, an attacker can exploit it while following the rules, and the blockchain will faithfully record the result.

"It was audited, so it's safe" also deserves caution. An audit reviews specific code at a specific time; it does not cover later upgrades or contracts outside its scope.

07

Before you use a contract

A dapp combines a front end with contracts on the blockchain, so both need checking. Ethereum.org's overview of dapp architecture is a useful reference. A sensible sequence:

  1. Find the contract address in the project's official documentation and compare it with the address in your wallet's signing prompt.
  2. In a block explorer, check that the contract source is verified and review its deployment date and upgrade history.
  3. Read the audit report's date and scope, and whether reported issues were fixed.
  4. See whether admin powers are limited by a multisig or timelock, and who controls any emergency pause.
  5. Start with a small amount and set token approvals no higher than you need.
08

What code cannot do for you

A smart contract executes its rules precisely, but whether those rules are fair or safe depends on the people who wrote and reviewed them. If something goes wrong, there may be no intermediary to reverse it or compensate you.

The escrow example is hypothetical. When using a real service, rely on official documentation and current audit materials, paying attention to publication dates, and only commit amounts you could afford to lose.