Skip to main content

Voting

DReps, Constitutional Committee members, and Stake Pool Operators can vote on governance actions. Evolution SDK's vote operation submits voting procedures in a transaction.

Casting a Vote

Build a VotingProcedures object with a voter, the governance action to vote on, and your vote (yes/no/abstain):

import { DRep, GovernanceAction, TransactionHash, VotingProcedures, preprod, Client } from "@evolution-sdk/evolution"

const client = Client.make(preprod)
.withBlockfrost({
baseUrl: "https://cardano-preprod.blockfrost.io/api/v0",
projectId: process.env.BLOCKFROST_API_KEY!
})
.withSeed({ mnemonic: process.env.WALLET_MNEMONIC!, accountIndex: 0 })

declare const drep: DRep.DRep
const voter = new VotingProcedures.DRepVoter({ drep })

declare const govActionTxHash: TransactionHash.TransactionHash
const govActionId = new GovernanceAction.GovActionId({
transactionId: govActionTxHash,
govActionIndex: 0n,
})

const procedure = new VotingProcedures.VotingProcedure({
vote: VotingProcedures.yes(),
anchor: null,
})

const votingProcedures = VotingProcedures.singleVote(voter, govActionId, procedure)

const tx = await client.newTx().vote({ votingProcedures }).build()
const signed = await tx.sign()
await signed.submit()

Vote Options

FunctionMeaning
VotingProcedures.yes()Vote in favor
VotingProcedures.no()Vote against
VotingProcedures.abstain()Explicitly abstain

Voter Types

VoterCredential TypeScript-Controlled?
DRepKey hash or script hashYes
Constitutional CommitteeHot credential (key or script)Yes
Stake Pool OperatorPool key hashNo (key-hash only)

Script-Controlled Voting

import { Data, VotingProcedures, preprod, Client } from "@evolution-sdk/evolution"

const client = Client.make(preprod)
.withBlockfrost({
baseUrl: "https://cardano-preprod.blockfrost.io/api/v0",
projectId: process.env.BLOCKFROST_API_KEY!
})
.withSeed({ mnemonic: process.env.WALLET_MNEMONIC!, accountIndex: 0 })

declare const votingProcedures: VotingProcedures.VotingProcedures
declare const votingScript: any

const tx = await client
.newTx()
.vote({
votingProcedures,
redeemer: Data.constr(0n, []),
label: "drep-vote"
})
.attachScript({ script: votingScript })
.build()

const signed = await tx.sign()
await signed.submit()

The builder automatically detects script-controlled voters and will fail if a redeemer is required but not provided.

Next Steps