
Swapping tokens without a middleman, borrowing against collateral, minting an NFT, voting in a DAO. Behind each of these actions sits a smart contract: a program on a blockchain that executes the rules it was given. There is no ordinary cancel button for a confirmed transaction, and no one can guarantee you get your money back.
From here on it is mechanics, with no marketing wording. What the network charges a fee for, and why reading from a contract is sometimes free. How approve differs from swap. Why code cannot look up the price of bitcoin on its own. How an "immutable" contract gets updated through a proxy.
The topic feels abstract right up until you sign a transaction that sends your money to the wrong place.
A smart contract is a program that lives on a blockchain at its own address and runs on the network's nodes (the computers that verify operations) when a transaction calls it. A contract has code, storage (its permanent memory) and a balance. The examples below come from Ethereum; in other networks the details differ. On Ethereum a contract is an account just like a regular user's, except that it has no private key: the code written into it is what controls it.
The name misleads: there is no intelligence in these programs, only automation. The term smart contract came from Nick Szabo: in 1994 he described the idea of conditions that execute on their own. Code by itself is not yet a legal agreement. The network executes what the code says, even if the code was written badly.
The contract's compiled code is open to everyone, and independent nodes re-check every operation. Not even the author can swap the rules out quietly: a change is possible only where the code itself allows it, and it is visible to all. An operation that has gone through cannot be reversed. How blocks and confirmations work is covered in a separate article "What Is Blockchain in Simple Terms".
The vending machine comparison came from the same Nick Szabo.
You drop in a coin, press the button, take the can. There is no salesperson, no cashier and no negotiation between you and the machine. Put in the right amount and you get the product. Put in less and nothing happens. The machine makes no exceptions and cannot change its mind.
The analogy needs three clarifications.
First. The machine does not chase you down the street: until someone presses a button, it does nothing. A contract does not start itself either. A change of state on the network begins with a transaction that someone sent and paid for; local reads work differently.
Second. The machine sees only the coins dropped into it. It knows nothing about the dollar rate, the weather or the news. A program on a blockchain likewise sees only what is recorded on the network.
Third, and the worst one. If the mechanism is faulty and the machine hands out two cans instead of one, there is no one to fix it. A line of takers forms within minutes. Same with a contract: a bug in the code is available to everyone at once.
A developer writes the code (most often in Solidity), compiles it into bytecode (instructions for the virtual machine) and sends a deployment transaction. The contract gets an address, and from that moment its code cannot be changed.
Calling a function is the same kind of transaction as sending ETH, except that the data field says which function to run and with which parameters. Nodes execute the code in the Ethereum Virtual Machine (EVM), and every one of them arrives at the same result.
Gas. Computation on the network is measured in units of gas. A plain ETH transfer costs 21,000 units. Calling a contract costs more, because gas for running the code and writing to storage is added on top of the base 21,000. The fee equals the gas used multiplied by its price: the base fee plus a tip. The network burns the base part; the tip goes to the validator that included the transaction in a block.
A sample calculation at a base fee of 8 gwei and a tip of 1 gwei, so 9 gwei per unit of gas (1 gwei is one billionth of an ETH):
The calculation shows the formula, not a current rate. Gas consumption depends on the token contract and the protocol (an application built out of contracts), and the gas price moves with network load. On layer-two networks (L2s, built on top of Ethereum) the fee is usually lower, but there is no universal "ten times cheaper": it all depends on the network and its load.
A failed transaction costs money too. The changes roll back, and the fee for the computation already performed is taken anyway.
Reading: free and paid. A free read is an eth_call request. A wallet or a site asks a node to run a contract function and return the answer. No transaction is created, nothing is written to the blockchain, no gas is charged: the node computes locally and the rest of the network takes no part in it. That is how an interface shows you a balance or an exchange rate before you have signed anything.
A paid read happens inside a transaction. During a swap, for instance, the exchange contract asks a pool (a contract holding a reserve of two tokens) how much it has in reserves. Every node performs that request, and each access to storage costs gas. It goes into the fee of the same transaction, though reading is cheaper than writing.
The number on your screen came from an eth_call, and by the time your transaction executes it may be out of date.
approve and swap. The first is permission, the second is the exchange. In the classic flow these are two separate transactions.
An ERC-20 token is a contract too, and the balances of all holders are recorded in its storage. An outside contract will not take your tokens without permission. The approve function records a limit in the token contract: a given address (the router contract of a decentralized exchange, for example) may withdraw up to a given amount from your balance. The tokens themselves do not move.
Then comes the swap: a second transaction, this time to the exchange contract's address. Within the limit, the router takes your tokens with transferFrom and passes them to the pool, the amount you receive is calculated from the pool's reserves, and the pool sends you the second token. The parameters include a minimum amount to receive. If by the time of execution the pool is ready to give less than that minimum, the swap reverts, and you still pay the fee for the attempt.
A swap with a separate approve costs more, since there are two transactions (ETH itself needs no approve: ETH is not an ERC-20 token). That is why interfaces often ask for permission for an unlimited amount, so that you do not have to pay for an approve before every swap. That permission stays in force after the swap as well. If the contract holding it gets hacked, or was malicious from the start, your entire remaining balance of that token can be taken from your address. Disconnecting your wallet from the site cancels nothing: revoking a permission is a separate transaction with a fee. I would set the limit to the size of the specific trade, even at the cost of an extra approve.
Oracles. A contract cannot visit an exchange's website and look up a rate. The reason is determinism. Every node has to arrive at the same result, and an external request could return a different value to each of them.
An oracle is a service that delivers outside information onto a blockchain. The oracle's nodes obtain the price off-chain and write it by transaction into a dedicated contract, which protocols then read. Decentralized oracle networks poll several independent nodes and reduce their answers to a single value (by taking the median, for example).
The risk does not go away. A price can be stale if an update was delayed. More dangerous still is a protocol that reads the current price straight from a decentralized exchange pool. An attacker takes a flash loan (an uncollateralized loan repaid within the same transaction), shifts the price in the pool with a large purchase and immediately borrows more than they should against the overvalued collateral. The protocol's code worked without error. It simply believed a wrong price.
Proxies and upgradability. Protocols get around the ban on changing code by using a proxy. A proxy is an intermediary contract: users interact with it, balances and settings sit in its storage, and it holds almost no logic. It forwards every call to an implementation contract through delegatecall. That instruction takes the code from another contract but runs it against the proxy's own storage. To update the protocol, the team writes the address of a new implementation into the proxy. The address users deal with and the balances stay the same; the logic changes.
If the logic can be replaced, then some address has the right to replace it. And even without a proxy, code often leaves the administrator special rights, such as pausing the contract. Check whether the contract can be upgraded and who holds the key: a multisig (a wallet where several owners confirm an operation) with a timelock (a mandatory delay before a change takes effect) is one level of risk; a single address belonging to an unknown owner is another one entirely.
DeFi (decentralized finance) is the area where code took the place of the bank and the broker: exchange, lending and derivatives all run through contracts. For how the whole ecosystem fits together, read the separate piece "What Is DeFi in Simple Terms".
A classic decentralized exchange works as an automated market maker. Two tokens sit in a pool, the price is set by the ratio of the reserves (Uniswap v2 uses the formula x × y = k, where x and y are the reserves of the two tokens), and a swap goes against the pool rather than against someone else's limit order. There is no order book (a list of limit orders to buy and sell) in pools like these.
Lending protocols hold the collateral in a contract and calculate the position's health factor (how well the collateral covers the debt). On Aave, liquidation (forced repayment of the debt out of the collateral) becomes possible once the factor drops below 1. Any network participant can trigger it. They repay the borrower's debt and take collateral of the same value plus a premium.
Contracts are public and call each other without permission, so a new protocol is assembled out of ready-made modules (this is called composability). The flip side: a bug in a lower module hits everything built on top of it.
An NFT (non-fungible token) is a record in a contract (most often an ERC-721 one) that ties a unique identifier to an owner's address. The image itself is usually not stored on the blockchain, because that is far too expensive. The contract holds a link to the description and the picture, and those sit on IPFS (a distributed file network) or on an ordinary server.
What the code records:
The ERC-2981 standard tells the marketplace the size of the cut, but it does not force anyone to pay: its text calls the payment voluntary outright, because moving a token between wallets does not yet mean a sale. Marketplaces make use of that. In August 2023 OpenSea announced a switch to optional royalties.
Beyond pictures, the same mechanism issues tickets and domain names.
A DAO (decentralized autonomous organization) is a treasury and a set of rules written into a smart contract. How the rules get changed depends on how a particular DAO is built and on what powers its administrators have. Governance token holders put forward proposals and vote. Voting weight usually equals the number of tokens at an address.
In some DAOs an approved decision executes automatically, by a transaction from the contract. In others the vote only records the participants' will, and specific people from a multisig sign the transfer.
A governance token trades on the market, which means influence can be bought. When turnout is low, a handful of large holders decide the outcome.
The price of a bug in code was shown by The DAO, an investment fund run by code, back in 2016. A reentrancy vulnerability (the contract sent funds before it updated the balance) allowed more than 3.6 million ETH to be drained from it. The community voted for a hard fork (an incompatible change to the network's rules) that returned the funds to depositors.
Immutable code protects against the rules being swapped out, but because of it a bug in a deployed contract cannot be fixed after the fact, and what is stolen usually does not come back.
According to a report by the analytics firm TRM Labs dated 1 July 2026, there were 207 hacks in the first half of the year, more than in any six-month period it has tracked. The amount stolen was 972 million dollars, less than half of the 2.3 billion in the first half of 2025.
Of the 207, 125 came through smart contract vulnerabilities, but they accounted for a small share of the total. Around 76% of the stolen funds came from roughly 15% of incidents. Those are attacks on infrastructure and operational processes: on systems, on access, and on the signing keys used to control assets.
The classes of vulnerability in code repeat year after year:
A story of its own is the malicious signature. The ERC-2612 standard (the permit function, which not every token has) and schemes like Permit2 make it possible to grant permission to spend tokens by signing a message instead of by transaction. No gas is charged for a signature, and it does not appear in the address's history. Later the recipient of the signature submits it to the blockchain themselves and takes the tokens. On a fake site a signature like this can look like a harmless "log in to the app".
Typical user mistakes. Nothing has to be hacked here; the user hands everything over himself.
An audit is a review of the code by an independent team before launch or before a major update. Auditors read the code by hand, run analyzers, model attacks and deliver a report with the findings graded by severity.
That lowers the risk but gives no guarantee. Ethereum's documentation says it plainly: an audit does not find every bug, and treating it as a silver bullet is a mistake.
Check three things in the report. Who did the review and what that team's reputation is. Which version of the code was reviewed and when: if the contract was updated afterwards, the code running on the network is no longer the code described in the report. Whether the severe findings were fixed, or only "acknowledged".
The telling case is the lending protocol Euler Finance. By the team's own account, it was audited far more often than is usual in the industry. In March 2023 the protocol still lost around 197 million dollars, because the donateToReserves function was missing a single check of the position's state. Over the next three weeks the funds were recovered, but that outcome is rare.
Beyond the report, it is worth finding out whether the project has a reward for reported vulnerabilities (a bug bounty), how long the protocol has been running with real money, and whether there is a timelock on sensitive changes.
Before entering any protocol, I would work out who can change the contract, what permissions it will receive, and what amount I would not mind losing in full.
Trading on a centralized exchange happens without smart contracts. When you open a position on Binance or Bybit, no code executes on a blockchain. The exchange's internal system matches the orders, and the blockchain is involved only when you deposit and withdraw funds.
Contracts affect the market in another way, through events that are visible on the blockchain.
Token unlocks. The schedule for releasing tokens to the team and to investors (vesting) is often written into a contract, and the dates are known in advance. A large unlock increases circulating supply, but the recipients are under no obligation to sell.
Liquidations in lending protocols. As soon as a position becomes eligible for liquidation, any participant can close it, and the transaction is visible to everyone. In a sharp price drop, liquidations like these can add to the selling in a market that is already heading down.
Fees belong here as well: for arbitrage between venues, the gas on a transfer is a direct cost that can eat the entire price difference. Large transfers to exchange addresses are visible immediately too, but a deposit is not yet a sale, since the tokens could have been posted as collateral or simply moved.
When this does not work. An event on the blockchain gives context, but on its own it is not an entry signal. An unlock whose date has been known for months is something the market knows in advance, and the price may react before the event, not react at all, or move against the obvious scenario. Shorting purely because of a line in the unlock calendar means trading someone else's expectation.
The market's reaction to an event is checked through order flow. Is the density level in the order book (a large limit order or a cluster of orders at one price) still sitting there, or was it pulled? Does the tape (the stream of executed trades with their size and side) show market selling picking up, or silence? Clusters (volume broken down by price inside a candle) will tell you which levels the turnover went through. These signs give no guarantees, because an order can be pulled at any moment. But choosing an entry point and a stop level from them makes more sense.
How to read the order book and clusters together is shown in the free lesson on the Secret Terminal YouTube channel. It is part of the full five-part crypto trading course for beginners.
This material is educational and contains no investment advice.
It is a program on a blockchain that automatically executes the conditions built into it when a transaction calls it. It works like a vending machine: the condition is met, the result is delivered, and the operation cannot be reversed. The word "smart" in the name is about automation only, not about intelligence.
That depends on the code. If it has no owner or administrator roles, then no one controls the contract after launch. Often the code does leave the administrator special rights: pausing the contract, changing parameters and, with a proxy deployment, replacing the logic. Before you put money in, check what rights the administrator has and who holds the key.
Gas pays for computation and for writing to the blockchain: a plain ETH transfer costs 21,000 units of gas, and calling a contract costs more. A read through eth_call is free, because no transaction is created and the node computes the answer locally. That same read inside a transaction consumes gas.
The approve function gives a contract permission to take your tokens up to a limit, while the tokens themselves stay where they are. A swap is a separate exchange transaction that uses that permission. An unlimited permission stays in force after the swap, until you revoke it.
No. Every node has to arrive at the same result, so the code cannot reach out to external sites. Prices are delivered onto the blockchain by oracles. Attacks are built on this: a DeFi protocol is fed a stale or artificially shifted price.
No. An audit lowers the chance of a bug, but it describes a specific version of the code on a specific date and does not catch everything. Euler Finance was audited more than once and in March 2023 still lost around 197 million dollars over one missed check.
Not automatically. Executing code is not the same as performing a contract: whether such an agreement is recognized depends on the jurisdiction and on how the parties documented their relationship off the blockchain. If it comes to a dispute, it will have to be settled through the ordinary legal route.
Smart contracts run on a blockchain, while trades on a centralized exchange go through the order book. Secret Terminal brings the order book with its density map, the tape and cluster analysis for Binance, Bybit, OKX, MEXC, WhiteBIT, Kraken and BloFin together in one window. The terminal is free. Download it from the official site, connect your exchange and look at the market at the level of orders and trades rather than candles.

Has 5 years of trading experience and spent 3 years as a mentor, training over 2,000 students. He is developing Secret Terminal to make professional trading tools accessible to every trader.
Was helpful
Your rating will help us improve the quality of published materials and increase their usefulness.
We publish product updates, setup guides, and practical materials on working with Secret Terminal tools

What working toward a result in trading consists of: the idea, entry and exit conditions, position size, fees and a jour...

How to choose when to trade crypto: volume, spread, news and your own routine. We explain crypto trading sessions and cl...

What a scalper does on an exchange and how the work is set up: short trades, the order book, time & sales, fees and the ...