Operate crypto with copy trading at BitgetSponsoredCreate Account at Bitget
vending machines, classical analogy of smart contracts
Learn

What is Smart Contract: How Smart Contracts Work

From Nick Szabo's sales machine to Ethereum: What they are, where they are on a daily basis, risk of bugs and care when signing transactions.

Image: Matti Blume, CC BY-SA 4.0, via Wikimedia Commons

By Boletim Bitcoin newsroom

. 11 min reading.

In short: Smart Contract, or smart contract, is a program stored on a blockchain that automatically executes rules like "if this, then that", without relying on an intermediary. The idea was described by Nick Szabo in the 1990s and gained scale with Ethereum, launched in 2015. Smart Contracts are the basis of stablecoins, decentralized exchanges, loans in DeFi, NFTs and tokens. The advantage is the predictable and public execution; The risk is that an error in the code can be exploited and, in general, there is no way to undo the transaction. Despite the name, a Smart Contract is usually not a legal contract.

Smart Contracts in Numbers

1994Nick Szabo writes the first introduction to the concept
2015launch of Ethereum, which popularized the contracts
~US$ 50 millionIn Ether taken in the attack on The DAO in 2016
21.000Gas units of a simple ETH transfer

When you exchange a token in a decentralized exchange, deposit a stablecoin to earn interest or purchase an NFT, you are interacting with a Smart Contract. Even those who have never written a line of code use these programs all the time in the crypto world. This guide explains what they are, how they work, where they are used, what the risks are and how to interact with them more safely. If you need, start with what is blockchain e What is Ethereum.

What is a Smart Contract

According to the ethereum.org, Smart Contracts are programs stored in Ethereum that follow the logic "if this, then that" and are guaranteed to execute according to the rules of the code, which cannot be changed after it is created. The Wikipedia Defines how a program or protocol that runs, controls or documents events automatically according to the terms of a contract.

In practice, the smart contract has an address on the blockchain, saves balances and data, and exposes functions that anyone can call by sending a transaction. When the programmed conditions are met, it runs alone: transfer tokens, register a loan, release a payment.

Traditional contractSmart contract
Text in Natural LanguageProgramming code
Interpreted by people and, if necessary, by a judgeRun automatically over the network
Can be renegotiated or changedIn general cannot be changed after published
Compliance depends on the parties or justiceFulfillment guaranteed by the Code, for good and for evil
Often private termsCode and Public Transactions

The sales machine analogy

The most used comparison comes from the creator of the term itself. Nick Szabo quoted the automatic vending machine: you choose the product, enter the right amount and receive the item; If you don't pay enough, you get nothing. There is no seller or negotiation. The ethereum.org Uses the same image: "Specific inputs guarantee predetermined outputs".

Smart Contract is a digital sales machine, but it can handle money, bonds, collectibles and much more complex rules. And, unlike a physical machine, it runs on thousands of computers at the same time, which prevents someone from turning it off or changing the rules on their own.

From Nick Szabo to Ethereum

  1. 1994Nick Szabo writes an introduction to the concept of smart contracts, according to Wikipedia.
  2. 1996Szabo deepens what these contracts could do.
  3. 1998Szabo designs Bit Gold, a digital currency never implemented, precursor to Bitcoin.
  4. 2009Bitcoin brings a limited, purposefully simple scripting system.
  5. 2014Vitalik Buterin publishes the Ethereum white paper, with a complete programming language.
  6. 2015Ethereum is released and allows general-purpose smart contracts.
  7. 2015Fabian Vogelsteller proposes the ERC-20 standard for tokens.
  8. 2016Attack on The DAO takes about $50 million in Ether and triggers a hard fork.

A Szabo biography on Wikipedia He recalls that he graduated in Computer Science and Law, a combination that explains his interest in bringing contractual rules to electronic commerce between strangers. see too Who is Vitalik Buterin?.

How a Smart Contract works inside

On Ethereum, the developer writes the contract in a language like Solidity or Vyper, compiles to bytecode and publishes it on the network with a transaction. From there, the contract gains an address and starts to run on Ethereum Virtual Machine (EVM), the "world computer" replicated on all nodes. Each operation consumes gas, the unit that measures the computational effort and is paid in ETH. Vide gas rate on ethereum.

According to the ethereum.org, the fee is due even if the transaction fails, because the network has already spent resources to process it. This explains why interactions with complex contracts, such as an exchange in DEX, cost more than a simple transfer of 21,000 units of gas.

  1. The developer writes and tests the code.
  2. Publishes the contract with a transaction; The contract receives an address.
  3. Users call contract functions by sending transactions signed by the wallet.
  4. The network nodes run the code and arrive at the same result.
  5. The new state (balances, records) is recorded on the blockchain.

Where smart contracts are in everyday life

UseWhat the contract doesRead more
StablecoinsIssues and burns tokens linked to the dollarstablecoins
TokensControls balances and transfers (ERC-20 standard)coin vs token
Decentralized exchangesExchange tokens using liquidity poolswhat is DEX
DeFi loansReceives guarantees and automatically releases loanswhat is DeFi
NFTsRegisters who owns each single itemWhat is NFT
TokenizationRepresents real assets such as bonds and real estatetokenization

The ERC-20 standard, described in ethereum.org, shows the strength of standardization: how all compatible tokens expose the same functions, such as transfer, approve and balanceof, wallets and exchanges can handle any of them without adaptation. In Brazil, the project DREX, the real digital It also tested smart contracts on a licensed network.

Risks: When the code is the law, the bug is also

Immutability is virtue and problem. "After a Smart Contract is published, it cannot be updated", summarizes the Wikipedia. If there is an error, anyone can see it and try to exploit it, and blockchain transactions usually cannot be reversed.

The most famous case is The DAO in June 2016: an attacker explored a failure and took about $50 million in Ether. The Ethereum community made a hard fork to return the funds, a controversial decision that gave rise to the Ethereum Classic. Wikipedia also cites attacks on Parity's multisig wallets and an overflow attack in 2018, which together exceeded US$ 184 million. Vide Biggest crypto hacks in history.

RiskExampleHow to reduce
Bug in codeThe DAO (2016)Prefer contracts audited and with history
Admin keyProject that changes rules or freezes fundsCheck who controls updates
Manipulated oracleFake price used to settle loansDesigns with robust price sources
Unlimited approvalMalicious contract drains approved tokensApprove only the necessary amount and revoke later
Blind signatureUser signs transaction that they do not understandRead the transaction; Use wallets that translate data

How to interact with more secure contracts

Ethereum.org warns of the risk of "blind signature": the raw data of a transaction is difficult to read, and the user ends up approving something they don't understand. The ecosystem moves to legible signature patterns, such as the ERC-7730. Meanwhile, some practices help:

  • Check the contract address on the project's official website, never in ad links or messages.
  • Prefer projects with public audits and years of operation without serious incidents.
  • When approving tokens, limit the amount to the necessary and revoke old approvals.
  • Use a separate, low-balance wallet to test new apps.
  • Keep most of the assets in hardware wallet.

More tips on crypto security checklist e scams with cryptocurrencies.

Is Smart Contract a real contract?

Not always. Wikipedia notes that a Smart Contract is typically not a legally binding agreement; There is the concept of "Smart Legal Contract", a legal contract in natural language with machine-readable terms. American states such as Arizona, Iowa, Nevada, Tennessee and Wyoming passed laws on the subject, and the British and Wales Law Commission concluded in 2021 that smart legal contracts can be recognized by English law.

In Brazil, there is no specific law on smart contracts. Contracts may have parts executed by code, but the rules of the Civil Code continue to apply. For those who invest, the lesson is simple: the code executes what is written, and complaining later may have no one.

Smart Contracts Beyond Ethereum

Ethereum popularized the model, but today several networks run smart contracts: Solana, BNB Chain, Avalanche, Cardano and Ethereum's own layer 2 networks, such as Arbititrum and Optimism. In Bitcoin, scripts are more limited by design, but updates like Taproot have broadened the possibilities. Vide cryptocurrencies layer 2, Taproot e Solana vs Ethereum.

This guide is educational and is not an investment recommendation. Smart Contracts based applications can contain flaws and lead to total loss of funds.

Frequently asked questions

What is Smart Contract in Portuguese?

Smart Contract means Smart Contract: a program saved in a blockchain that automatically executes rules, in the format "if this, then that", without intermediary. It is used in stablecoins, decentralized exchanges, DeFi loans, NFTs and tokens, mainly in Ethereum.

Who invented the Smart Contract?

The concept was described by computer scientist and lawyer Nick Szabo, who wrote an introduction to the topic in 1994 and deepened it in 1996, using the sales machine as an example. The idea gained scale with Ethereum, launched in 2015 from Vitalik Buterin's white paper.

Smart Contract can be changed?

In general, no. Once published, the code becomes immutable on the blockchain. Some projects use upgradeable contracts through admin keys or proxy structures, which brings flexibility, but also risk: who controls the update can change the rules.

How much does it cost to use a smart contract?

Each interaction pays a network fee, called gas in Ethereum, proportional to the computational effort. A simple transfer uses 21,000 units of gas; Complex contracts use much more. The fee is charged even if the transaction fails, because the network has already processed the request.

Are smart contracts safe?

It depends on the code. Contracts audited and tested for years are more reliable, but none are risk-free. Bugs have already caused major losses, such as the attack on The DAO in 2016, with about $50 million in Ether taken. Blockchain transactions usually cannot be reversed.

Is Smart Contract legal valid in Brazil?

There is no specific law in Brazil. A Smart Contract is usually not, in itself, a legal contract. He can execute parts of an agreement, but the rules of the Civil Code continue to apply. Some American states and England have already dealt with the subject in law or official opinion.

Does Bitcoin have Smart Contracts?

It has a more limited scripting system, purposefully simple to favor security. Updates like Taproot have extended the possibilities, but complex general-purpose contracts are mainly on networks like Ethereum, Solana and Layer 2 networks.

References

  1. ethereum.org: Smart contracts
  2. Wikipedia: Smart contract
  3. Wikipedia: Nick Szabo
  4. ethereum.org: ERC-20 token pattern
  5. ethereum.org: Gas and fees
  • smart contract
  • smart contract
  • Ethereum
  • DeFi
  • Solidity
  • guide

This content is informative and is not an investment recommendation. found an error? Write to contato@boletimbitcoin.com.

Read also

Learn

Fundamentalist Indicators Quiz

Test if you know how to calculate and interpret P/L, P/VP, Dividend Yield, LPA, EV/EBITDA and Net Debt/EBITDA. 8 questions with explanation.

Start at Bitget Today

Open your Bitget account and access Spot, Futures, Copy Trading and Trading Robots in one app.

  • Copy trading
  • Spot and futures
  • Trading robots
  • All-in-one app
Advertising. Crypto involves risk, invest responsibly.
Create Account at Bitget