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

Receive Function

1 min read
Pronunciation
[ri-seev fungk-shun]
Analogy
The receive function is like a mailbox slot that only accepts letters (Ether) but ignores packages (data‑bearing calls).
Definition
A Solidity function declared as `receive()` that executes only when a contract receives plain Ether with empty calldata.
Key Points Intro
Receive functions handle direct Ether transfers through:
Key Points

Signature: `receive() external payable` only.

Empty calldata: Triggered when no data is sent.

Fallback precedence: Called before fallback if defined.

No arguments/return: Cannot process data or return values.

Example
A vault contract uses `receive() external payable { balances[msg.sender] += msg.value; }` to credit deposits automatically.
Technical Deep Dive
When a contract is sent Ether without calldata (`address(contract).transfer(1 ether)`), the EVM invokes `receive()` if present; otherwise it falls back to `fallback()`. It runs with the full remaining gas, not the 2300‑gas stipend, enabling more complex logic than fallback.
Security Warning
Unbounded logic in `receive()` can lead to denial‑of‑service if gas runs out; keep operations simple.
Caveat
Only triggers on empty calldata; calls with data still invoke fallback.

Receive Function - Related Articles

No related articles for this term.