Cast Vote
Placing onchain votes for Onyx Improvement Proposals.
The castVote
function allows an eligible voter to cast their approval or disapproval on a governance proposal. The voting power of an account is determined based on the number of votes delegated to it at the time the proposal transitioned into the Active state.
Function Implementation in CHNGovernance
CHNGovernance
The castVote()
function ensures that only eligible voters can participate in governance decisions, maintaining the integrity of the Onyx governance system.
Function Signature
Parameters
proposalId
: The unique identifier of the governance proposal on which the vote is being cast.support
: A boolean value indicating the vote choice:true → Vote in favor of the proposal (Yes)
false → Vote against the proposal (No)
RETURN
: The function does not return a value. If the proposal ID is invalid or the voter is ineligible, the transaction reverts with an error.
Example Solidity Implementation
To cast a vote using Solidity, the castVote()
function can be called from an instance of the CHNGovernance
contract:
Web3.js Implementation (v1.2.6)
For interacting with the CHNGovernance
contract using Web3.js, the following example demonstrates how to cast a vote:
Technical Considerations
The
castVote()
function is state-modifying and will incur gas costs.Votes are weighted based on the voting power at the moment the proposal became Active.
If the voter has not been delegated voting power, they cannot cast a vote.
Once a vote is cast, it cannot be changed unless the
castVoteWithReason
function (if available) is used.Proposal outcomes depend on the total votes cast before the voting period ends.
Governance dashboards and vote tracking tools should integrate this function to allow real-time monitoring of voting activity.
Last updated