Skip to content

What is a smart contract?

A smart contract is a program at a blockchain address that runs fixed rules when called. Anyone can read it, and its code stays fixed unless built to upgrade.

evmquery team5 min readEthereum, explained, part 1 of 13

What is a smart contract?

A smart contract is code that carries out fixed rules automatically whenever someone calls it. It is not a legal contract and it has no intelligence: it does exactly what it was written to do.

Common examples are TokenA token is a digital asset tracked by a smart contract, such as a stablecoin, a game item or a membership pass.See it in the glossaryRead the explainer, swap sites, lending apps and NFT collections. Each one has its own AddressAn address is the public identifier of a wallet or contract on Ethereum, a long string starting with 0x.See it in the glossary. A token such as USDC is a ledger kept by a contract, as the ERC-20 guide shows.

Smart contract vs a normal service

A normal service keeps its rules inside a company, which can change them at any time. A smart contract keeps its rules in public code that anyone can read. You can inspect the rules instead of taking them on trust.

Two panels. Left: rules kept by a clerk, where a company can change them and you trust the staff. Right: rules kept by code, called a smart contract, where everyone sees the same rules.
With a clerk you trust people. With a contract you can read the rules yourself.

This does not make a contract safe by default. Code can contain mistakes, and its authors may hold special powers.

How smart contracts work

A smart contract is code and stored data at one address on the chain. The code is a list of named actions, called functions. The stored data holds the facts those functions use, such as balances or owners.

A box labelled with a contract address, 0xA0b8 dots eB48, holds two parts. Rules, which are the functions or code. Memory, which is the storage holding balances and owners. A note says anyone can call a function and the contract answers.
One address, two parts: the rules (functions) and the memory (storage).

A token contract might offer balanceOf, which looks up one balance, and transfer, which moves tokens. Its memory holds every balance.

A contract address looks like the address of your WalletA wallet is the app or device that holds your keys and lets you sign transactions and view your assets.See it in the glossary, but no person holds a key that speaks for it. Many computers on the network run the code and compare results, so you do not have to trust any single operator.

What happens when you call one?

Reading asks a question and changes nothing, so it is free. Writing changes the contract’s memory, so the whole network has to record it.

Two panels. Reading is free and changes nothing, for example asking how much USDC exists. Writing is a transaction that costs gas and changes the record, for example sending 10 USDC.
Reads are free questions. Writes are paid changes.

A write is sent as a TransactionA transaction is a signed instruction that changes something on the blockchain, such as sending ETH or calling a contract.See it in the glossary. You sign it with your wallet, the network checks it, and the contract runs the function you named. The fee is called GasGas measures the computing work a transaction needs, and you pay for it in small amounts of ETH.See it in the glossaryRead the explainer, and you pay it even if the contract refuses the request.

A contract cannot start itself, so it never acts on a schedule unless someone calls it. It also cannot reach into your wallet. To move your tokens, an app needs an approval that you sign. If a transaction fails, the contract’s changes are undone, so an action either completes fully or not at all.

Can a smart contract be changed?

By default, no. Once deployed, a contract’s code stays as written, and nobody can edit it, not even its authors. That suits fixed rules and makes bugs hard to fix.

Teams that want room to fix things build the contract so it forwards calls to a second contract that holds the logic. They can later point it at a new version. This pattern is called a ProxyA proxy is a contract at a fixed address that forwards calls to another contract, which lets the logic be upgraded.See it in the glossaryRead the explainer, and the proxy contracts guide explains it.

Many large contracts use it, USDC among them. The address stays the same while the logic behind it can change. The free Proxy Detector shows whether any address is upgradeable.

How is a smart contract created?

A developer writes the rules in a language built for contracts, most often Solidity. A compiler turns that text into low-level instructions the chain can run. The developer then publishes it by sending a transaction with no recipient.

The network stores the code and gives the contract its own address. From then on anyone can call it. Many teams publish the readable source on a block explorer so people can check that it matches the running code.

Most of what you do on Ethereum passes through a contract. Sending a stablecoin, swapping on an exchange and buying an NFT each call one. The same design runs on many chains, which is why tools for Ethereum usually work on Base, BNB Chain and Polygon. The EVM guide explains why.

See it on a real contract

The card below reads the current USDC supply from the contract on Ethereum. It is a stored value returned by one function, with no company asked for it.

USDC in circulation on Ethereum

Reading live from Ethereum

Inspect USDC in the Contract Inspector

Show the queryformatUnits(usdc.totalSupply(), usdc.decimals())

Paste the same address into the Contract Inspector to see its full function list and whether it is a proxy.

Common mix-ups

  • “A smart contract is a legal agreement.” It is a program that carries out fixed steps. A legal contract can be written around one, but the program has no legal standing.
  • “Smart contracts are always safe because they are code.” Code can have bugs, and an upgradeable contract can change. Read the contract and check for a proxy first.
  • “A contract can run by itself.” It runs only when a person, an app or another contract calls it.
  • “The company behind a token controls the contract.” That depends on whether the code gives special powers to an address, and the code shows which.

Summary

  • A smart contract is a program at a blockchain address that runs fixed rules when someone calls it.
  • Anyone can read a contract for free, and changing it costs a fee called gas.
  • A contract’s code cannot be edited after launch unless its authors built in a way to swap the logic.

For developers

You can read any contract function without an ABI file or a node, and one request can carry several reads. See smart contract ABI explained for how functions are described and encoded.

Share

Read any smart contract with one request

Create a free API key and read live data from any contract on Ethereum, Base, BNB Chain or Polygon.