LogoLogo
  • Introduction
    • Chain Info
    • Smart Contracts
    • About Onyx
  • DEVELOPERS
    • Building dApp
    • Estimating Gas
    • Development Framework
    • Web3 Toolkits
    • Onyx SDK
    • Run Full Node
  • GOVERNANCE
    • Overview
    • Governor
    • Security
    • Quorum Votes
    • Proposal Threshold
    • Proposal Max Operations
    • Voting Delay
    • Voting Period
    • Propose
    • Queue
    • Execute
    • Cancel
    • Get Action
    • Get Receipt
    • Proposal State
    • Cast Vote
    • Vote By Signature
    • Timelock
  • Points
    • Onyx Points
    • Earning Points
      • 🟢Passive Points
      • 🔜Activity Points
      • 🔜App Points
  • Whitelisted Assets
  • Onyx AI
    • AI Agent
    • Core Features
    • Wallet Infrastructure
    • 🔜Roadmap
  • API
    • Onyx Governance API
    • Core API Endpoints
    • GET: /proposal
    • GET: /proposal/:proposalId
    • GET: /voter/:proposalId
    • GET: /voter/accounts
    • GET: /voter/history/:address
  • RESOURCES
    • Terms of Service
    • Bug Bounty
Powered by GitBook
On this page
Export as PDF
  1. GOVERNANCE

Vote By Signature

Vote through an offline signature for cold wallets.

The castVoteBySig function allows an offline signer to participate in Onyx governance voting by submitting a digitally signed vote. Unlike the castVote function, which requires the voter to be online and execute the transaction, this function enables voting via an EIP-712-compliant signature, making it useful for delegated and gasless voting.

Function Implementation in CHNGovernance

The castVoteBySig() function ensures that votes can be cast securely and efficiently using off-chain signatures, reducing the need for direct blockchain interaction while maintaining the integrity of the voting process.

Function Signature

function castVoteBySig(
    uint proposalId,
    bool support,
    uint8 v,
    bytes32 r,
    bytes32 s
) 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)

  • v: The recovery byte of the signature, used for ECDSA signature verification.

  • r: First half of the ECDSA signature pair.

  • s: Second half of the ECDSA signature pair.

  • RETURN:The function does not return a value. If the proposal ID is invalid or the signature is not valid, the transaction reverts with an error.

Example Solidity Implementation

To cast a vote using Solidity, the castVoteBySig() function can be called from an instance of the CHNGovernance contract:

CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.castVoteBySig(proposalId, true, v, r, s); // Voting in favor using an offline signature

Web3.js Implementation (v1.2.6)

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

const tx = await gov.methods.castVoteBySig(proposalId, false, v, r, s).send({}); // Voting against using an offline signature

Technical Considerations

  • The castVoteBySig() function is state-modifying and will incur gas costs.

  • Votes are weighted based on the voting power at the moment the proposal became Active.

  • EIP-712-compliant signatures ensure the security and authenticity of the vote.

  • If the signature is invalid or does not match the voter's address, the transaction reverts with an error.

  • This function allows users to sign a vote offline and have another address submit the vote on-chain, enabling gasless voting if subsidized by a third party.

  • Governance interfaces and voting dashboards should support offline signing workflows to increase accessibility and voter participation.

PreviousCast VoteNextTimelock

Last updated 3 months ago