Sub topic 6
Governance tokens: voting rights as a token
A governance token is a token whose main function is to give its holder a say in how a protocol or organization is run. This chapter explains what that say covers, how the vote weight is computed, and where the design breaks down in practice. It assumes you know what a smart contract is, how ERC-20 tracks balances, and the difference between a coin and a token from earlier chapters. You should also be able to read short Solidity snippets.
What a governance token represents
A governance token represents the right to take part in decisions. Those decisions usually concern a protocol: a lending market, an exchange, or a stablecoin system. Typical decisions include:
- Changing parameters, such as a fee rate or a collateral limit.
- Spending money from a shared treasury.
- Upgrading contracts or adding new features.
- Appointing or removing people who hold special roles.
The token is a counter of influence. Holding 2% of the voting supply means you control 2% of the votes. It does not mean you own 2% of the protocol's revenue, assets, or legal entity. A token can carry economic rights too, but that is a separate design choice. Many governance tokens grant no claim on revenue at all.
Technically, nothing special is needed for the token to exist. The ERC-20 standard only tracks balances. Governance is added in a second layer: contracts that read those balances (or a record of them) and count votes.
Token-weighted voting
The most common rule is one token, one vote. If a proposal gets 3 million votes in favor and 1 million against, it passes, subject to the other rules covered in the next chapter, such as quorum.
This has three consequences you should keep in mind:
- Influence follows capital. A holder with ten times the tokens has ten times the weight.
- Tokens can be bought. Anyone who acquires tokens acquires votes. This is a feature for openness and a weakness for security.
- Tokens can be moved. A balance that is counted during a vote can be sent elsewhere right after, and the receiving address could vote again. The system must prevent this double counting.
The third problem explains why governance tokens are more than plain ERC-20 contracts.
Why a plain balance is not enough
Suppose a voting contract simply reads balanceOf(voter) at the moment of voting. An attacker could vote with a balance, transfer the tokens to a second address, and vote again from there. Even without such tricks, a flash loan (a loan borrowed and repaid within one transaction) could supply a huge temporary balance.
The standard fix is a snapshot. When a proposal is created, the system fixes a past point in time, such as a block number. Voting weight is the balance the voter held at that point. Tokens bought after the snapshot do not count for that proposal, and tokens sold after it still do.
To look up past balances cheaply, the token records checkpoints: a history of each account's voting power, updated whenever tokens move. The token can then answer "what was this account's voting power at block N?" without replaying all transfers. Checkpoints are covered in detail two chapters later. Here you only need to know that they are what makes snapshots possible.
Delegation: voting power is opt-in
In the widely used OpenZeppelin implementation, ERC20Votes, holding tokens does not give you voting power automatically. You must first delegate. Delegation assigns your voting power to an address. That address can be your own or someone else's. Your tokens stay in your wallet, and only the voting weight moves.
Delegation has two practical uses:
- Self-delegation activates your own votes. This is the step many new holders miss.
- Delegation to others lets people who lack time or expertise hand their weight to a representative, such as a delegate who publishes voting reasons.
The reason for requiring a delegate step is gas cost. Writing a checkpoint on every transfer for every holder would be expensive. Requiring delegation means the contract tracks voting power only for accounts that opted in.
A governance token in code
This contract extends ERC-20 with OpenZeppelin's ERC20Votes (version 5). ERC20Votes records vote checkpoints on every transfer. ERC20Permit is included because the Governor tooling commonly pairs with it, and it lets users approve and delegate with signatures instead of separate transactions.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import {ERC20Votes} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
import {Nonces} from "@openzeppelin/contracts/utils/Nonces.sol";
contract GovToken is ERC20, ERC20Permit, ERC20Votes {
constructor() ERC20("Gov Token", "GOV") ERC20Permit("Gov Token") {
_mint(msg.sender, 1_000_000 * 10 ** decimals());
}
function _update(address from, address to, uint256 value)
internal
override(ERC20, ERC20Votes)
{
super._update(from, to, value);
}
function nonces(address owner)
public
view
override(ERC20Permit, Nonces)
returns (uint256)
{
return super.nonces(owner);
}
}Three points about this code:
- The two overrides are required because several parent contracts define
_updateandnonces. Solidity forces you to state how they combine. Neither override changes behavior here. _updateis whereERC20Voteshooks in. Every mint, burn, and transfer adjusts the checkpoints of the delegates involved.- The constructor mints the whole supply to the deployer. Who then holds that supply is a tokenomics question, covered in the supply and vesting chapter. Governance is only as decentralized as that initial distribution.
After deployment, nobody has voting power, not even the deployer. The deployer must call delegate(deployerAddress) first. A sketch of the lifecycle:
// Called by the holder, for example from a script or wallet
govToken.delegate(msg.sender); // activate own votes
govToken.getVotes(msg.sender); // current voting power
govToken.getPastVotes(msg.sender, blockNumber); // weight at a past blockgetPastVotes is the function a Governor contract calls with the proposal's snapshot block.
How the pieces fit together
The token supplies weight. A separate set of contracts, often called a Governor and a timelock, runs the proposal process. The diagram shows the flow from token holder to executed decision.
The next chapter walks through the steps from the Governor onward: proposals, quorum, and timelocks.
On-chain and off-chain governance
Not every governance token is counted by a smart contract that executes results automatically.
| Approach | How votes are counted | What happens after a pass | Trade-off |
|---|---|---|---|
| On-chain | A Governor contract reads checkpoints | The contract executes the change itself | Binding and transparent, but each vote costs gas and the code must be secure |
| Off-chain (signed messages) | Signatures are collected and weighed against a snapshot | A multisig or team applies the result | Cheap and fast, but relies on people to follow through |
Many projects use both. A cheap off-chain poll gauges opinion, and a binding on-chain vote follows.
Governance versus other token types
A token can have several roles, and the labels overlap. A protocol may issue one token that is also used to pay fees (utility) and to vote (governance). The key question is what the token is required for:
- If the protocol cannot be used without the token, it behaves as a utility token.
- If the token's only job is to steer decisions, it is a governance token.
- If neither is true and value rests on attention, it is closer to a memecoin, even if a vote feature is attached.
A token with a voting function but no real decisions to make has weak governance demand. The vote is only valuable if the decisions it controls are meaningful, such as access to a treasury or control of important parameters.
Common errors
- Forgetting to delegate. The balance shows tokens, but
getVotesreturns zero. - Assuming transfers carry delegation. Delegation attaches to the holder's choice. A recipient of tokens must delegate for the new tokens to count.
- Treating total supply as the electorate. Locked, vesting, or exchange-held tokens may not vote, so the active electorate is smaller.
- Confusing voting rights with ownership. Votes control a protocol's parameters. They do not entitle holders to profits unless the design says so.
- Trusting a vote without reading the timelock. A decision that can execute immediately gives holders no time to react to a malicious proposal.
Exercise
A holder buys 50,000 GOV tokens on an exchange and sends them to their own wallet. A proposal's snapshot was taken yesterday. Today the holder calls delegate on their own address and then tries to vote. Their weight is zero. Give two reasons this could be the case.
Show answer
First, the snapshot was taken before the purchase, so getPastVotes at the snapshot block returns the balance and delegation state at that time, which did not include the new tokens. Second, even if the snapshot were later, voting power only exists for delegated tokens, and checkpoints are written at the time of delegation or transfer. Delegation made after the snapshot does not alter the past record. The holder must delegate and hold the tokens before a proposal's snapshot to vote on it.
Exercise
Why does OpenZeppelin's ERC20Votes require holders to delegate instead of counting every balance automatically?
Show answer
Recording checkpoints for every holder on every transfer would raise gas costs for all users. Requiring delegation means the contract only tracks voting power for accounts that chose to participate, whether delegating to themselves or to someone else.