# Cast Vote

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`

The `castVote()` function ensures that only eligible voters can participate in governance decisions, maintaining the integrity of the Onyx governance system.

#### Function Signature

```
function castVote(uint proposalId, bool support) public
```

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:

```
CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.castVote(proposalId, true); // Voting in favor of the proposal
```

#### Web3.js Implementation (v1.2.6)

For interacting with the `CHNGovernance` contract using Web3.js, the following example demonstrates how to cast a vote:

{% code overflow="wrap" %}

```javascript
const tx = await gov.methods.castVote(proposalId, false).send({ from: sender }); // Voting against the proposal
```

{% endcode %}

#### 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onyx.org/governance/cast-vote.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
