Ethereum and Smart Contracts: How They Work Together
Ethereum runs smart contracts: code that carries out agreements automatically when conditions are met. How the two fit together, what gas pays for, and the limits.
On this page
Short answer
Ethereum is a public blockchain that runs programs called smart contracts, which carry out the terms of an agreement automatically once their conditions are met. A smart contract lives at an address on Ethereum, holds its own rules and state, and runs exactly as written whenever someone sends it a transaction. You pay gas for the computing work each run uses.
What are Ethereum and smart contracts?
Ethereum is a public blockchain that runs programs called smart contracts. A smart contract is code stored on the blockchain, together with the data it keeps, that runs exactly as written whenever someone calls it. Nobody can change the code after it is deployed, and nobody needs permission to read it.
The idea is simple: instead of a person or a company carrying out each step of an agreement, the steps are written as rules in code. When the conditions in the code are met, the contract acts. A token contract moves tokens when a payment arrives. An escrow contract releases money when a delivery is confirmed. A voting contract counts votes and reports the result.
Ethereum is the network that makes this possible at scale. It keeps a shared record of every contract, every balance and every change, and thousands of independent computers check each new block against the same rules. That shared checking is what lets strangers trust the outcome without trusting each other. For the building blocks, Ethereum development covers how teams put contracts into production.
How does a smart contract run on Ethereum?
A smart contract runs on Ethereum through the Ethereum Virtual Machine, a computing environment that every node on the network reproduces. When you send a transaction to a contract, each node runs the same code with the same inputs and reaches the same result. If the result changes any stored data, that change is written into a new block.
The run follows a fixed sequence:
- You sign a transaction from a wallet, naming the contract and the function to call.
- The transaction is broadcast to the network and picked up by a block builder.
- Each node runs the contract code and checks that the call is valid.
- The result is recorded in a block, and the contract state is updated for everyone.
- Anyone can read the result on a block explorer, with no account needed.
Because every node repeats the work, running code on Ethereum costs more than running it on a normal server. That cost is the trade for a result nobody can rewrite after the fact. A guide to deploying smart contracts on Ethereum walks through the five stages from writing the code to verifying it.
What can smart contracts do on Ethereum?
Smart contracts on Ethereum can move value, record decisions and enforce rules without a middleman. The most useful ones do a small job well and leave the rest to ordinary software. The table below shows the common patterns and what each one needs to work.
| Use | What the contract does | What it needs |
|---|---|---|
| Tokens | Tracks who owns how many units | A fixed supply rule |
| Escrow | Holds payment until delivery is confirmed | A trusted confirmation signal |
| Lending | Lends against collateral and liquidates it | A price feed and collateral rules |
| Marketplaces | Lists items and settles sales on the spot | Clear ownership records |
| Voting | Counts votes and enforces the outcome | A fair way to count each voter once |
| Insurance payouts | Pays out when a named event happens | A reliable source for the event |
Every row depends on good inputs. A contract cannot check the real world by itself, so it relies on an outside source, called an oracle, for facts such as a delivery confirmation or a market price. If that source is wrong, the contract still runs exactly as written, which is why the input design matters as much as the code.
What is gas, and why do you pay it?
Gas is the unit that measures the computing work a transaction needs on Ethereum, and you pay for it in ETH. Each step a contract runs costs a fixed amount of gas, so a simple token transfer costs far less than a complex trade that touches several contracts. The fee goes to the people who run the network, not to the contract itself.
Gas exists for two reasons. First, it stops abuse: without a cost, anyone could flood the network with work that every node must repeat. Second, it rations a shared resource. When many people want their transactions included at once, those who pay more per unit of gas are picked up first, and the price rises with demand.
Three facts help you plan around gas:
- Reading is free. Asking a contract for its current state costs nothing, because no node has to record a change.
- Writing costs gas. Any call that changes stored data needs a transaction and a fee.
- Failed calls still cost gas. If a transaction runs out of gas or fails a check, the work already done is still paid for, though no state changes.
Before you ship, test on a test network and measure the gas each function uses, so users are not surprised by the cost of the most common actions.
How do you interact with a smart contract?
You interact with a smart contract by sending it a transaction from a wallet, or by reading its public data without any wallet at all. The contract itself has no website and no login screen. The websites and apps you see are front ends that format the same calls a wallet can make directly.
Read calls and write calls behave differently:
- Read calls ask for current data, such as a token balance or a vote count. They are free and instant, and they change nothing.
- Write calls change state, such as sending tokens or casting a vote. They need a signed transaction, cost gas, and take time to confirm in a block.
Before you send value to a contract, check it on a block explorer. The explorer shows the contract address, its verified source code if the author published it, and the full history of calls and transfers. If the code is not verified, you cannot tell from the address alone what it will do. A plain explanation of Ethereum is a useful starting point if the terms here are new.
Example (hypothetical): a simple escrow
Example (hypothetical): a buyer agrees to pay a freelance designer 300 units for a logo, in three milestones of 100 units each. The buyer deposits 300 units into an escrow contract. The contract holds the money and releases 100 units each time the buyer confirms a milestone is done.
The arithmetic is straightforward. Three releases of 100 units add up to the full 300 units, so the designer is paid exactly what was agreed. Each release is a write call that costs 2 units of gas, so the three releases cost 6 units in total. The buyer therefore spends 306 units altogether: 300 for the work and 6 for the three transactions.
The contract adds two things a plain bank transfer does not. The designer can see the 300 units sitting in the contract before starting work, which proves the buyer can pay. And the buyer knows the money cannot move until each milestone is confirmed, which keeps the payment tied to delivery.
If the two sides disagree, the contract cannot settle the argument by itself, so a good escrow names an arbitrator who can decide, and that role should be written into the contract from the start.
What are the common mistakes?
The most common mistakes with Ethereum smart contracts are treating code as if it were the whole agreement, ignoring gas costs, and trusting a website instead of the contract itself.
- No review before deployment. Code cannot be changed after it is deployed, so a bug in a payment rule stays live. Get an independent smart contract audit for anything that holds real value.
- Forgetting the upgrade path. If the rules may need to change, plan for it in advance with a proxy or a new contract, and tell users how changes will be decided.
- Ignoring gas in the design. A contract that loops over a growing list gets more expensive with every user, until the call costs more than it is worth.
- Trusting the front end. A website can show one address and send transactions to another. Always confirm the contract address on a block explorer.
- Putting secrets on chain. Everything stored in a contract is public. Passwords, private keys and personal data do not belong there.
- Weak inputs. A contract that pays out on a price feed or a delivery signal is only as honest as that feed.
Key takeaways
- Ethereum is a public blockchain that runs programs called smart contracts, which act automatically when their conditions are met
- Every node runs the same code and reaches the same result, which is what makes the outcome hard to rewrite
- Gas pays for the computing work a transaction uses; reading is free, writing costs gas
- Contracts cannot check the real world alone, so they rely on outside sources for facts such as prices and deliveries
- Verify the contract address and code on a block explorer before sending value to it
Frequently asked questions
Is Ethereum the only blockchain with smart contracts?
No. Other blockchains run smart contracts too, but Ethereum is the oldest large network for them and has the most tools, wallets and audited code. Teams pick a chain based on fees, speed, tooling and where their users already are, not on the idea alone.
Do I need ETH to use a smart contract?
You need ETH to pay gas for any call that changes state, such as sending tokens or voting. Reading data from a contract is free and needs no ETH. Some apps pay the gas for their users, but the cost is still paid by someone.
Can a smart contract be changed after deployment?
The code itself cannot be changed, which is the point of deploying it. Teams that need changes use a proxy contract that points at new code, or deploy a new contract and move users over. Both approaches need to be planned before launch, not after.
What happens if a smart contract has a bug?
A bug stays live until the contract is replaced or its upgrade path is used, and funds can be stuck or drained in the meantime. That is why contracts that hold value are reviewed and audited before deployment, and why simple, small contracts are safer than large ones.
How do smart contracts get real-world information?
They read it from an outside source called an oracle, such as a price feed or a delivery confirmation service. The contract trusts whatever the oracle reports, so the choice of oracle and how it is checked matters as much as the contract code.
Are smart contracts legally binding?
It depends on the jurisdiction and the agreement around the code. A contract can enforce the mechanics, such as releasing payment, while the legal rights still rest on the written agreement between the parties. Get legal advice before relying on code alone.