ERC-1202 · Review · ERC · 2018-07-08
ERC-1202: Voting Interface
A minimal standard interface for casting on-chain votes on a proposal ID, so voting UIs and DAOs can work with any compliant voting contract.
What problem does it solve?
Voting is one of the oldest things people built with smart contracts, and every DAO needs it. But each voting contract exposes its own functions and events, so a general voting UI, an indexer or another contract that wants to "vote automatically" has to be written for each one separately.
ERC-1202 defines a small common surface: cast a vote on a proposal, record it with a standard event, and execute the result. Anything built on that surface can talk to any compliant contract.
How it works
The spec deliberately keeps a lot out of scope: delegation, how voting weight or eligibility is calculated (snapshots, quadratic voting…), what a proposal contains, and off-chain signature aggregation. Proposals are just a uint256 proposalId. Related ideas are left to separate proposals such as ERC-5247 (executable proposals) and ERC-5453 (endorsements).
What it does require:
IERC1202Core(mandatory):castVote,castVoteFrom(vote on behalf of another address),execute, and theVoteCastevent. A vote carriessupport(auint8option, chosen for compatibility with GovernorBravo), aweight, areasonUriand free-formextraParams.IERC1202MultiVote(optional, required if you support multiple options per voter, e.g. ranked choice):castMultiVotewith arrays of options and weights.IERC1202Info(described for reading): the voting period for a proposal and a voter's eligible weight.- Compliant contracts SHOULD implement ERC-5269 so callers can discover which interfaces they support.
Sample code
The core interface plus a toy one-address-one-vote implementation (illustrative; the spec's listing omits return types, so this sketch returns nothing):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IERC1202Core {
event VoteCast(address indexed voter, uint256 indexed proposalId,
uint8 support, uint256 weight, string reason, bytes extraParams);
function castVote(uint256 proposalId, uint8 support, uint256 weight,
string calldata reasonUri, bytes calldata extraParams) external payable;
function castVoteFrom(address from, uint256 proposalId, uint8 support, uint256 weight,
string calldata reasonUri, bytes calldata extraParams) external payable;
function execute(uint256 proposalId, bytes memory extraParams) external payable;
}
contract SimpleVote is IERC1202Core {
mapping(uint256 => mapping(uint8 => uint256)) public tally;
mapping(uint256 => mapping(address => bool)) public voted;
function castVote(uint256 id, uint8 support, uint256, string calldata reason,
bytes calldata extra) external payable {
require(!voted[id][msg.sender], "already voted");
voted[id][msg.sender] = true;
tally[id][support] += 1; // weight fixed at 1 here
emit VoteCast(msg.sender, id, support, 1, reason, extra);
}
function castVoteFrom(address, uint256, uint8, uint256, string calldata,
bytes calldata) external payable { revert("not supported"); }
function execute(uint256, bytes memory) external payable { /* app-specific */ }
}
Things to know
- Status: Review. The interface has changed substantially over the years (it dates from 2018), so check the current text before building on it.
- The standard says nothing about who may vote or how weight is computed; your implementation must define and enforce that, and
weightpassed by the caller should not be trusted blindly. - On a public chain votes are visible; the spec notes that real anonymity needs cryptographic techniques beyond this interface.
- It flags bribery as a risk: once votes are on-chain and standard, another contract can pay people to vote a certain way.
- Production DAOs commonly use audited governor frameworks; treat this ERC as an interoperability layer, not a complete governance system.