0Pricing
Web3 & DApp Development Fundamentals · บทเรียน

ไทม์ล็อกและการดำเนินการ

การอัปเกรดอย่างปลอดภัย

ไทม์ล็อกและการดำเนินการ เป็นบทเรียน Web3 & DApp Development Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Web3 & DApp Development Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Why Timelocks Exist

A timelock is a mandatory delay between when a proposal passes and when it executes.

It protects users by giving them time to react to changes they disagree with — for example, withdrawing funds before a risky upgrade.

The TimelockController

OpenZeppelin's TimelockController is a contract that schedules, delays, and then executes operations.

The Governor proposes and queues actions into the timelock, which actually owns the protocol's admin rights.

contract Timelock is TimelockController {
    constructor(uint minDelay, address[] proposers, address[] executors)
        TimelockController(minDelay, proposers, executors, msg.sender) {}
}

Schedule, Wait, Execute

Operations flow through three steps:

  • schedule — queue the action with a delay
  • wait — the minDelay must elapse
  • execute — run the action after the delay
timelock.schedule(target, value, data, predecessor, salt, delay);
// ... wait minDelay ...
timelock.execute(target, value, data, predecessor, salt);

The minDelay Parameter

The minDelay sets how long every scheduled operation must wait. Common values range from 1 to 7 days.

Longer delays mean more safety but slower governance — a deliberate trade-off each DAO must tune.

Roles in the Timelock

The timelock uses access roles:

  • PROPOSER — can schedule operations (the Governor)
  • EXECUTOR — can run them after the delay
  • ADMIN — manages roles (often renounced)

Timelock Owns the Protocol

For governance to be meaningful, the timelock contract should hold the protocol's admin and ownership rights — not any individual.

This ensures every privileged change must pass through the full govern-then-delay pipeline.

protocol.transferOwnership(
    address(timelock)
);

Defense Against Malicious Proposals

If an attacker sneaks a harmful proposal through voting, the timelock delay is the last line of defense.

The community can spot the queued action and exit or coordinate a response before it executes.

Predecessor and Salt

Each scheduled operation can specify a predecessor (an operation that must run first) and a salt to make its identifier unique.

These let DAOs order dependent operations and avoid hash collisions between similar actions.

Cancelling Operations

A scheduled operation can be cancelled before execution by an address with the canceller role.

This provides an emergency brake if a queued action is found to be dangerous during the delay window.

timelock.cancel(operationId);

Upgrades Done Safely

Combining Governor + Timelock + a proxy pattern lets DAOs upgrade contracts safely: vote, queue, delay, then execute the upgrade.

Every step is transparent and reversible up until execution, balancing flexibility with security.

Putting It Together

The timelock enforces a delay between approval and execution, owns the protocol's privileges, and uses roles plus cancellation to keep upgrades safe.

It is the crucial buffer that makes on-chain governance trustworthy.

Quick Check

Test your timelock understanding.

Recap: Timelocks and Execution

You learned that:

  • A timelock delays execution after a proposal passes
  • TimelockController schedules, waits, then executes
  • minDelay tunes the safety vs speed trade-off
  • The timelock should own the protocol; roles control access
  • Operations can be cancelled during the delay

Course complete! Next course: Layer 2 and Scaling.

คำถามที่พบบ่อย

บทเรียน “ไทม์ล็อกและการดำเนินการ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ไทม์ล็อกและการดำเนินการ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Web3 & DApp Development Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ไทม์ล็อกและการดำเนินการ”

การอัปเกรดอย่างปลอดภัย คุณปฏิบัติ Web3 & DApp Development Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Web3 & DApp Development Fundamentals หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Web3 & DApp Development Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “ไทม์ล็อกและการดำเนินการ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Web3 & DApp Development Fundamentals นี้ได้ไหม

ได้ บทเรียน Web3 & DApp Development Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. DAO คืออะไร
  2. โทเค็นธรรมาภิบาล
  3. ข้อเสนอและการลงคะแนน
  4. ไทม์ล็อกและการดำเนินการ
← กลับไปที่ Web3 & DApp Development Fundamentals