What is a smart contract? An example

THE SHORT ANSWER

A smart contract is a program stored on a blockchain, executed when a transaction calls its functions. It applies rules written in code. It can contain bugs and does not, by itself, establish legal rights or prove that external data is true.

Smart Contracts Fundamentals

A smart contract stores code and data at a blockchain address. A transaction can call a function to apply its programmed rules.

Practical Application

A ticketing program can assign a token after receiving the required payment. Actual access to the event still depends on the organizer and ticket terms.

Technical Infrastructure

Languages and Platforms

On Ethereum, languages such as Solidity and Vyper produce code executed by the network’s virtual machine. Other chains and layer 2 networks have their own environments and trade-offs: code compatibility does not mean identical risks.

Security and Auditing

Tests and audits help identify defects without guaranteeing their absence. Administrative permissions and external dependencies also matter.

Security and Immutability

Some contracts cannot be changed directly; others use upgrade mechanisms. Understanding who can change program behavior is essential.

Key Features

  • Deployed code can be inspected; readable source code is not always published or verified.
  • Reading data can happen without a transaction; changing state requires authorized execution.
  • External information, such as a price, depends on an oracle or another data input.
  • An audit covers a scope and version. Upgrades, administrative keys and other contracts add dependencies.

Applications and Use Cases

Decentralized Finance (DeFi)

Contracts can calculate a swap or manage loan collateral. Incorrect price data or a code error can cause a loss even when the program executes exactly as instructed.

Tokenization and NFTs

Smart contracts define rules for creating and transferring tokens. Transaction history tracks the token but does not prove the authenticity of an external item or its associated rights.

What code can guarantee

Code automates certain rules. It does not replace risk assessment or checking the rights associated with a service.

Sources and further reading

Page updated on
Documentation checked on · WhyTheBlockchain · Editorial approach