โ
Previous Module
Deploy Your First Contract
๐ Calling Smart Contract Functions
Learn how to interact with contracts using view, pure, and payable functions
Your Progress
0 / 5 completed๐ Smart Contract Function Calls
Functions are the building blocks of smart contracts. Understanding how they call each otherโand the gas costs involvedโis essential for writing efficient, secure code.
๐ฎ Interactive: Function Call Types Explorer
Explore different types of function calls and their characteristics
๐
Internal Call
Function call within same contract
Gas Cost: Low (24-100 gas)
Characteristics:
1
Direct JUMP in EVM
2
Same context (storage, msg.sender)
3
No transaction overhead
4
Fastest execution
Code Example:
function a() { b(); } // b() is internal๐ค Why Function Calls Matter
โก
Gas Efficiency
Internal calls cost ~50 gas. External calls cost 2,600+ gas. Choose wisely!
๐ก๏ธ
Security
External calls can fail or be malicious. Always validate and handle errors.
๐๏ธ
Architecture
Call patterns determine contract composability and upgrade strategies.
๐ฏ
Optimization
Understanding calls helps you write lean, cost-effective smart contracts.
๐ What You'll Learn
1
Call Types & Mechanics
Internal, external, delegatecall, staticcallโhow each works under the hood
2
Gas Costs & Optimization
Measure real gas consumption and learn techniques to minimize costs
3
Security Patterns
Reentrancy guards, checks-effects-interactions, and safe call practices
4
Real-World Examples
See how DeFi protocols and token contracts use function calls efficiently
๐ Key Concepts Preview
internal
Same contract, JUMP opcode, preserves context, lowest gas
external
Different contract, CALL opcode, new context, higher gas
delegatecall
Execute in caller's context, proxy pattern, same gas as external
view / pure
Read-only, STATICCALL, cannot modify state, safe reads
payable
Can receive ETH, special handling, value transfer
reentrancy
Attack vector, checks-effects-interactions, use guards
๐ก Quick Example
contract Calculator {
// Internal call - just JUMP (cheap)
function add(uint a, uint b) internal pure returns (uint) {
return a + b;
}
// External call - calls add() internally
function calculate() public pure returns (uint) {
return add(5, 3); // Internal: ~50 gas
}
}
contract User {
Calculator calc = new Calculator();
function useCalculator() public view returns (uint) {
// External call - CALL opcode (expensive)
return calc.calculate(); // External: ~2,600 gas
}
}Notice: Same calculation, but external call costs 50x more gas! This module teaches you when to use each type.