Get Receipt
This function fetches a ballot detail for each specific voter based on a specific governance proposal.
The getReceipt
function retrieves the ballot receipt for a specific voter in relation to a particular governance proposal. This function enables governance participants and developers to track and verify voting activity, ensuring transparency in the decision-making process.
Function Implementation in CHNGovernance
CHNGovernance
The getReceipt()
function is implemented in the CHNGovernance
contract to return structured voting details for a given voter’s participation in a proposal.
Function Signature
Parameters
proposalId
: The unique identifier of the governance proposal being queried.voter
: The Ethereum address of the voter whose receipt is requested.RETURN:
If the function call is successful, it returns a Receipt struct, containing:hasVoted
(bool): Indicates whether the voter has already cast a vote.support
(uint): Represents the type of vote cast (e.g., For, Against, Abstain).votes
(uint): The number of votes the voter allocated to the proposal.
If the proposal ID is invalid, or the voter has not participated, the function reverts with an error.
Example Solidity Implementation
To retrieve a voter's ballot receipt using Solidity, the getReceipt()
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 retrieve a voter's receipt:
Technical Considerations
The
getReceipt()
function is a view function, meaning it does not modify blockchain state and can be executed without incurring gas costs.If the voter has not participated in the proposal, the function may return a default empty receipt or revert with an error.
This function is useful for governance dashboards, allowing stakeholders to track who voted, how they voted, and how many votes were cast.
Governance analytics tools should integrate this function to provide real-time voting insights.
Last updated