Crypto & Web3 · Explainer
What smart contracts are and how they work
A smart contract is a program that enforces rules by itself on a blockchain. See where the idea came from, how it works, where it tends to fail and where it fits in Brazilian law.
- Author:
- Redação Token & Tech
- Responsible editor:
- Daniel Ferreira
- Translation:
- Redação Token & Tech
Published · 8 min read
Originally published in Brazilian Portuguese.
Translated from the Portuguese original with AI assistance.
Also available in: Português
Key points
- A smart contract is a program stored at an address on the blockchain, with its own code and data, that always runs the same way when it receives the right inputs.
- It cannot see the real world without oracles and, by default, cannot be fixed after deployment: code bugs have already caused losses such as The DAO's in 2016.
- In Brazil, no federal law defines the term; in the newsroom's reading, code can execute an agreement, but the agreement's validity is still governed by the Civil Code.
The name is misleading. A smart contract is not a legal document written by artificial intelligence, nor a contract that “thinks”. It is a computer program stored on a blockchain that enforces rules automatically.
This article explains where the idea came from, how these programs work in practice, why a code bug can be costly and how the topic fits into Brazilian law. If you are not yet familiar with the network where most of them run, it is worth reading what Ethereum is and how it works first.
The original idea: the vending machine
The term comes from computer scientist Nick Szabo. In a 1996 text, he defined a smart contract as “a set of promises, specified in digital form”, including the protocols by which the parties perform on those promises (Szabo, 1996). Szabo himself warns that “smart” has nothing to do with artificial intelligence: it simply means more functional than paper.
The example he uses is the vending machine, which he calls the “primitive ancestor” of smart contracts. You insert the coins, choose the product and the machine dispenses the product and the change, with no seller. The rule is built into the equipment, and the potential loss for anyone who tries to cheat is greater than the gain.
At the time, there was no platform to put this into practice at scale. That only changed with programmable blockchains.
What a smart contract is today
As defined in the Ethereum documentation, a smart contract is a program that runs on the blockchain: a collection of code (its functions) and data (its state) that resides at a specific address on the network (ethereum.org, smart contracts). The documentation for Solidity, the most widely used language for writing them, describes it the same way: code and data that reside at an address (Solidity, introduction).
A few characteristics help explain what changes compared with an ordinary system:
- Deterministic execution. Every computer on the network runs the same code and reaches the same result. With the right inputs, the outcome is guaranteed by the rules.
- Permissionless deployment. Anyone who can code and has ether to pay the fee can deploy a contract.
- Composability. Contracts are public and work as building blocks that other contracts can call. That is how applications stacked on top of one another come about.
- Irreversibility. Interactions with a deployed contract cannot be reversed.
There are also less commonly mentioned technical limits. A contract on Ethereum has a maximum size of 24 KB, according to ethereum.org. Larger programs have to be split into several contracts.
How it works in practice
The basic flow has three steps:
- Write. The developer writes the contract in a language such as Solidity.
- Compile and deploy. The code is turned into bytecode, low-level instructions, and deployed to the network through a transaction. The contract gets an address.
- Call. People or other contracts send transactions to that address, calling functions. Each call consumes gas, the fee paid for processing.
The simplest example in the Solidity documentation is a contract that stores a number: one function writes the value and another reads it. An important detail: anyone can call the write function and overwrite the number, but the old values remain in the blockchain’s history. Restricting who can change what is the programmer’s job.
A common use case is multisignature wallets, contracts that only move funds when, for example, three of five authorized keys sign. The idea is to prevent the loss or theft of a single key from putting everything at risk. If key protection is your concern, see also how to protect your seed phrase.
What a smart contract cannot do
See the outside world
A contract does not look up websites, prices or game results on its own. This is by design: if each computer fetched external data at different times, it could get different answers, and the network would no longer reach consensus (ethereum.org, oracles).
The solution is oracles, services that publish external data on the blockchain. They create the so-called oracle problem: how do you know the data came from the right source, was not tampered with and is still being updated? A centralized oracle can make mistakes, go offline or be compromised. ethereum.org itself acknowledges that relying on oracle operators weakens the promise of doing away with trust.
Fix itself
Contracts on Ethereum are immutable by default: deployed code does not change. There are techniques to allow upgrades, such as proxy contracts, which redirect calls to a new version of the logic (ethereum.org, upgrading contracts).
But this comes at a cost. According to the documentation, users then have to trust that developers will not change the contract arbitrarily, and the upgrade function itself becomes a target. In other words: either the contract is rigid and cannot be fixed, or it can be fixed and someone has power over it.
Do away with trust entirely
The US standards institute, NIST, lists as a common misconception the idea that blockchains are “trustless” environments. Among the forms of trust that remain necessary, the report cites trust that smart contracts work correctly and without unforeseen loopholes (NIST IR 8202, 2018).
When code fails: The DAO and other cases
Since there are no reversals, a programming error becomes a real loss. The best-known case is The DAO, a collective investment contract on Ethereum. In 2016, an attacker exploited a flaw and drained more than 3.6 million ETH (ethereum.org, smart contract security).
The response was drastic. On July 20, 2016, at block 1,920,000, the network carried out a fork that moved the funds to a new contract, from which those who had lost money could withdraw 1 ETH for every 100 DAO tokens. Some miners rejected the change, on the grounds that the problem was not with the protocol, and kept the original chain, which came to be called Ethereum Classic (ethereum.org, history of forks). The episode shows that “code is law” has limits: when the loss was large, the community changed the rules.
The flaw exploited is known as reentrancy: a malicious contract calls back into the vulnerable function before it finishes updating the balance, and withdraws repeatedly. ethereum.org cites other cases: US$ 30 million taken in an attack on a Parity multisignature wallet and more than US$ 300 million in ETH permanently locked in another incident involving the same company’s wallets. The documentation estimates that losses from smart contract security flaws “easily” exceed US$ 1 billion.
The documentation’s own recommendations include independent audits, testing, automated code analysis, bug bounty programs and reuse of already audited libraries. It warns, however, that an audit is not a complete guarantee.
Smart contracts and Brazilian law
Here it is necessary to separate what the law says from what is interpretation.
What the law says. The newsroom did not find any Brazilian federal law that defines “smart contract”. The Civil Code establishes that a legal transaction is valid when there is a capable party, a lawful, possible and determined or determinable object, and a form prescribed or not prohibited by law (art. 104). A declaration of intent does not depend on any special form, except when the law requires one (art. 107). For rights in rem over real estate worth more than thirty minimum wages, a public deed is essential (art. 108). The contracting parties must act with probity and good faith in concluding and performing the contract (art. 422) (Civil Code).
Provisional Measure 2.200-2, of 2001, recognizes electronic documents and accepts other means of proving authorship and integrity, in addition to ICP-Brasil certificates (Brazil’s public key infrastructure), provided the parties accept them as valid (art. 10, § 2) (MP 2.200-2).
The newsroom’s reading. Based on the provisions above, a smart contract can be used to record and execute an agreement between capable parties, as long as the object is lawful and the law does not require a specific form. The code, however, does not replace the validity rules: an agreement with a defect of consent, an unlawful object or an inadequate form does not become valid because it was executed by a program. By the same logic, the transfer of a token does not, on its own, amount to the transfer of ownership of a property, a topic covered in does a token represent legal ownership of a property?. This is an editorial interpretation, not a legal opinion.
As an international reference, the Law Commission of England and Wales concluded, in advice published on November 25, 2021, that the existing law of that jurisdiction can accommodate so-called smart legal contracts without legislative reform, although it pointed to issues that require further study (Law Commission). The conclusion applies to that legal system, not to Brazil.
Risks for users
If you interact with applications based on smart contracts, the main risks are:
- Code bugs. A flaw can be exploited and funds lost with no possibility of reversal.
- Upgrade power. Upgradeable contracts depend on whoever controls the upgrade.
- Oracles. If the external data is wrong or manipulated, the contract executes based on the error.
- Scams. Malicious contracts may ask for approvals that allow your wallet to be drained. See how to spot cryptocurrency scams and how to protect yourself from wallet phishing.
- Total loss. Assets controlled by contracts can lose all their value, through technical or market failure.
Key takeaways
- A smart contract is a program on a blockchain, with code and data at an address. The idea comes from Nick Szabo, in the 1990s, and gained scale with Ethereum.
- It enforces rules predictably, but cannot see the real world without oracles and, by default, cannot be fixed.
- Code bugs have already caused losses of hundreds of millions of dollars; The DAO case, in 2016, led to a fork of the network.
- In Brazil, the validity of the agreement is still governed by the Civil Code. Code executes; it does not make valid what the law does not allow.
- To understand how the same technology is proposed for public records, read blockchain against record fraud.
Sources
- Smart Contracts: Building Blocks for Digital Markets, Nick Szabo (cópia do site original hospedada na Universidade de Amsterdã). Accessed October 8, 2026
- Introduction to smart contracts, ethereum.org. Accessed October 8, 2026
- Introduction to Smart Contracts (documentação do Solidity), Solidity (Ethereum Foundation). Accessed October 8, 2026
- Oracles, ethereum.org. Accessed October 8, 2026
- Upgrading smart contracts, ethereum.org. Accessed October 8, 2026
- Smart contract security, ethereum.org. Accessed October 8, 2026
- Timeline of all Ethereum forks (DAO fork), ethereum.org. Accessed October 8, 2026
- NISTIR 8202: Blockchain Technology Overview, National Institute of Standards and Technology (NIST). Published October 1, 2018 · Accessed October 8, 2026
- Lei nº 10.406, de 10 de janeiro de 2002 (Código Civil), texto compilado, Presidência da República (Planalto) (BR). Published January 10, 2002 · Accessed October 8, 2026
- Medida Provisória nº 2.200-2, de 24 de agosto de 2001 (ICP-Brasil e documentos eletrônicos), Presidência da República (Planalto) (BR). Published August 24, 2001 · Accessed October 8, 2026
- Smart contracts (projeto e parecer sobre smart legal contracts), Law Commission (Inglaterra e País de Gales). Published November 25, 2021 · Accessed October 8, 2026
Educational content. Not investment advice. This article is educational and informative. It is not a personalized recommendation to buy, sell or hold any asset. Crypto-assets and tokenized assets carry risks, including total loss; rules vary by jurisdiction.