0Pricing
Web3 & DApp Development Fundamentals · 课时

提案与投票

治理合约

提案与投票 是 CoddyKit 上的免费 Web3 & DApp Development Fundamentals 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web3 & DApp Development Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

The Governance Lifecycle

On-chain governance follows a clear lifecycle: propose, vote, queue, execute.

Each stage is handled by a Governor smart contract that enforces the rules automatically.

The Governor Contract

OpenZeppelin's Governor is the standard framework for DAO voting. It manages proposals, tallies votes, and triggers execution.

It is modular: you plug in a vote-counting strategy, a token, and timing parameters.

contract MyGovernor is
    Governor,
    GovernorVotes,
    GovernorVotesQuorumFraction,
    GovernorTimelockControl
{ /* ... */ }

Creating a Proposal

A proposal bundles the actions to execute: target contracts, call data, and values, plus a human-readable description.

governor.propose(
    [targetContract],   // addresses
    [0],                // ETH values
    [callData],         // encoded function calls
    "Increase reward rate to 5%"
);

The Voting Delay

After a proposal is created, a voting delay passes before voting opens.

This gives members time to review and lets the snapshot block settle so balances are fixed.

votingDelay  = 1 block   // wait before voting
votingPeriod = 50400 blocks // ~1 week of voting

Casting Votes

During the voting period, members cast votes weighted by their delegated power at the snapshot block.

Standard options are For, Against, and Abstain.

governor.castVote(proposalId, 1);
// 0 = Against, 1 = For, 2 = Abstain

Vote Counting and Quorum

When voting ends, the Governor tallies the weighted votes. A proposal succeeds only if it has more For than Against votes and meets the quorum.

Abstain votes typically count toward quorum but not toward the For/Against decision.

Proposal States

A proposal moves through defined states:

  • Pending — waiting for voting delay
  • Active — voting open
  • Defeated or Succeeded
  • Queued then Executed

Queuing a Successful Proposal

A succeeded proposal is usually queued in a timelock before it can run.

This delay (covered next lesson) is a safety buffer letting users react before the change takes effect.

governor.queue(targets, values, calldatas, descHash);

Execution

After the timelock delay, anyone can call execute to carry out the proposal's actions on-chain.

The Governor (or its timelock) holds the permissions needed to make the changes.

governor.execute(targets, values, calldatas, descHash);
// the approved actions now run

Gas Costs and Off-Chain Voting

On-chain voting costs gas per vote. To save costs, many DAOs deliberate and signal off-chain (Snapshot) and only push final, binding actions on-chain.

This hybrid keeps participation cheap while preserving trustless execution.

Putting It Together

Governor contracts standardize the propose-vote-queue-execute flow. Voting delays, periods, quorum, and proposal states make governance predictable and secure.

Next we focus on timelocks, the safety layer before execution.

Quick Check

Test your understanding of the governance flow.

Recap: Proposals and Voting

You learned that:

  • Governance follows propose, vote, queue, execute
  • The Governor contract enforces the rules
  • A voting delay and period structure the timeline
  • Success needs a majority For plus quorum
  • Proposals pass through defined states

Next: timelocks and safe execution.

常见问题解答

「提案与投票」课时是免费的吗?

是的 — 「提案与投票」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web3 & DApp Development Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。

「提案与投票」这节课中我会学到什么?

治理合约 你通过在浏览器中直接运行的动手代码来练习 Web3 & DApp Development Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Web3 & DApp Development Fundamentals 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Web3 & DApp Development Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「提案与投票」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Web3 & DApp Development Fundamentals 课中编写并运行代码吗?

能。每节 Web3 & DApp Development Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 什么是 DAO
  2. 治理令牌
  3. 提案与投票
  4. 时间锁与执行
← 返回 Web3 & DApp Development Fundamentals