Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

Smart Contract Function

1 min read
Pronunciation
[smart kon-trakt fuhngk-shuhn]
Analogy
Think of a smart contract as a vending machine. The 'functions' are the buttons on the vending machine. Each button, when pressed (called), triggers a specific action: dispense a soda, dispense chips, return coins, etc. Each function has a specific purpose and set of instructions it follows.
Definition
A callable unit of code within a smart contract that performs a specific task or set of operations when invoked. Functions define the contract's interface and behavior, allowing users and other contracts to interact with it.
Key Points Intro
Functions are the executable components that define a smart contract's capabilities.
Key Points

Named blocks of code within a smart contract that can be called externally by users (via transactions) or internally by other functions within the same contract or by other contracts.

Can accept input parameters and may return output values.

Can read or modify the smart contract's state.

Visibility modifiers (e.g., `public`, `private`, `internal`, `external` in Solidity) control who can call a function.

Example
An ERC-20 token contract typically has functions like `transfer(address recipient, uint256 amount)`, `balanceOf(address account)`, and `approve(address spender, uint256 amount)`. Users call these functions to interact with their tokens.
Technical Deep Dive
When a function is called, its code is executed by the blockchain's virtual machine (e.g., EVM). Functions that modify state consume more gas and are part of transactions that get included in blocks. Functions that only read state (view/pure functions) can often be called without sending a transaction (off-chain call), as they don't change the blockchain. Each function has a unique signature derived from its name and parameter types, which is used to identify it when called.

Smart Contract Function - Related Articles

No related articles for this term.