What Is a Smart Contract?

Transactions

A smart contract is a program that runs on the blockchain under specific conditions.

Koin Bülteni · Updated:

On this page
  1. What is a smart contract?
  2. A swap example
  3. Is it secure if the code is public?
  4. Source

What is a smart contract?

A smart contract is a program stored on the blockchain that operates according to predetermined rules. The code can execute when a user sends a transaction or when another contract calls it. Operations such as token transfers, swaps, lending, and voting can be conducted through these programs.

The word “smart” in its name does not mean the program thinks or makes decisions. The contract simply enforces the rules as they were written. Likewise, calling it a “contract” does not mean it automatically carries the weight of a legal contract in every country. Technical execution and legal binding are separate matters.

A swap example

Consider swapping token A for token B in an application. The swap contract executes the transaction using the amount you provide and the minimum return you accept. If the transaction terms are not met, the call may fail. In Ethereum, a fee for the computational resources used may still be paid for a failed transaction; the fact that the swap did not occur does not mean no fee will be charged.

In some token transactions, you first give the contract permission to spend your tokens. This approval is an authorization separate from the swap itself and may remain open even after the transaction is complete. Disconnecting your wallet from a website does not automatically revoke this permission on the blockchain.

Is it secure if the code is public?

Open-source code and independent audits help with scrutiny but do not guarantee the absence of errors. A poorly written calculation, issues with external price data, or the compromise of an admin key can lead to losses. Furthermore, some contracts are upgradeable; there may be a governance structure that allows the code you see today to be modified later.

When using an application, you need to understand which network you are on, which contract you are authorizing, and how the transaction will affect your balance. An attractive interface or a familiar logo is no substitute for this information.

Source