0Pricing
Blockchain Smart Contracts with Solidity · Ders

Değiştiriciler ve Kontroller-Etkiler-Etkileşimler Kalıbı

Ön koşulları temiz biçimde uygulamak için işlev değiştiricilerini kullanın ve daha güvenli sözleşmeler yazmak için kontroller-etkiler-etkileşimler kalıbını uygulayın.

Değiştiriciler ve Kontroller-Etkiler-Etkileşimler Kalıbı, CoddyKit'te ücretsiz bir Blockchain Smart Contracts with Solidity dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Blockchain Smart Contracts with Solidity öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Blockchain Smart Contracts with Solidity kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What Are Modifiers?

A modifier is reusable code that runs before (or around) a function body. It is ideal for enforcing preconditions like access control without repeating the same checks everywhere.

Declaring a Modifier

The special _; placeholder marks where the function body executes. Code before it runs first; code after runs when the function returns.

modifier onlyOwner() {
    require(msg.sender == owner, "Not owner");
    _;
}

Applying a Modifier

Attach a modifier to a function declaration. The check runs automatically on every call, keeping the function body focused on logic.

function withdraw() public onlyOwner {
    payable(owner).transfer(address(this).balance);
}

Modifiers with Parameters

Modifiers can take arguments, making them flexible for validating dynamic conditions such as minimum values.

modifier costs(uint price) {
    require(msg.value >= price, "Not enough");
    _;
}

Stacking Multiple Modifiers

You can apply several modifiers to one function; they run left to right. Keep them small and single-purpose so combinations stay predictable.

function buy() public payable onlyWhenOpen costs(1 ether) {
    // ...
}

The Reentrancy Danger

When a contract calls out to an external address, that address can call back into your contract before the first call finishes. This reentrancy can drain funds if state is updated too late.

Checks-Effects-Interactions

The checks-effects-interactions pattern orders your function in three phases: validate inputs (checks), update state (effects), then call external contracts (interactions). External calls come last.

A Vulnerable Withdraw

This sends ETH before zeroing the balance, leaving a reentrancy window.

// VULNERABLE
function withdraw() public {
    uint amt = balances[msg.sender];
    payable(msg.sender).call{value: amt}("");
    balances[msg.sender] = 0; // too late!
}

The Safe Version

Update state before the external call so a reentrant call sees a zero balance.

// SAFE
function withdraw() public {
    uint amt = balances[msg.sender];
    balances[msg.sender] = 0;   // effects first
    payable(msg.sender).call{value: amt}(""); // interaction last
}

Reentrancy Guards

For extra safety, add a reentrancy guard modifier that sets a lock flag during execution, rejecting nested calls. Libraries like OpenZeppelin provide nonReentrant.

Combining the Patterns

Use modifiers for the checks phase (access and validation), structure the body as effects-then-interactions, and add a guard on functions that move value. Together they form a strong defensive baseline.

Quick Check

Check your knowledge of safe contract patterns.

Recap

You learned defensive Solidity patterns:

  • Modifiers centralize preconditions like access control
  • They can take parameters and be stacked
  • Checks-effects-interactions orders functions to prevent reentrancy
  • Add a reentrancy guard on value-moving functions

These patterns are foundational to writing secure contracts.

Sıkça Sorulan Sorular

“Değiştiriciler ve Kontroller-Etkiler-Etkileşimler Kalıbı” dersi ücretsiz mi?

Evet — “Değiştiriciler ve Kontroller-Etkiler-Etkileşimler Kalıbı” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Blockchain Smart Contracts with Solidity kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Blockchain Smart Contracts with Solidity kursu toplamda 4 dersten oluşur.

“Değiştiriciler ve Kontroller-Etkiler-Etkileşimler Kalıbı” dersinde ne öğreneceğim?

Ön koşulları temiz biçimde uygulamak için işlev değiştiricilerini kullanın ve daha güvenli sözleşmeler yazmak için kontroller-etkiler-etkileşimler kalıbını uygulayın. Blockchain Smart Contracts with Solidity ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Blockchain Smart Contracts with Solidity öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Blockchain Smart Contracts with Solidity, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Değiştiriciler ve Kontroller-Etkiler-Etkileşimler Kalıbı” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Blockchain Smart Contracts with Solidity dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Blockchain Smart Contracts with Solidity dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Kalıtım ve Arayüzler
  2. Kitaplıklar ve Soyut Sözleşmeler
  3. Revert/Require ile Hata İşleme
  4. Değiştiriciler ve Kontroller-Etkiler-Etkileşimler Kalıbı
← Blockchain Smart Contracts with Solidity Sayfasına Dön