✅ Master Contract Function Interactions

Call functions safely, optimize gas usage, and implement access control

Previous
Security Patterns

🎓 Key Takeaways

Congratulations! You've mastered function calls in smart contracts. Let's review the essential concepts.

🔄
Internal Calls

Direct JUMP, same context, ~50 gas. Use for helper functions within same contract.

📡
External Calls

CALL opcode, new context, ~2,600 gas. Used for cross-contract interactions.

🎭
Delegatecall

Execute in caller's storage context. Foundation of proxy patterns and upgradeable contracts.

🔒
Staticcall

Read-only external calls that revert on state changes. Safer for view/pure functions.

Gas Optimization

Internal calls save 98% gas vs external. Choose wisely for 50x cheaper execution!

🛡️
Security

Reentrancy guards, checks-effects-interactions, and OpenZeppelin tools prevent attacks.

🧠 Test Your Knowledge

Answer all questions to complete the module

1. What is the approximate gas cost difference between internal and external function calls?
2. In DELEGATECALL, which contract's storage is modified?
3. What is the correct order for the Checks-Effects-Interactions pattern?
4. What makes reentrancy attacks possible?
5. Which call type automatically reverts if the target tries to modify state?

🚀 What's Next?

🔍
Practice Security Audits

Review real contracts on Etherscan. Can you spot reentrancy vulnerabilities?

Optimize Gas Costs

Refactor your contracts to use internal calls. Measure gas savings with Hardhat!

🎭
Build Proxy Patterns

Create upgradeable contracts using delegatecall and proxy patterns.

🛡️
Study OpenZeppelin

Deep dive into ReentrancyGuard, SafeERC20, and other security libraries.