Governance Transactions
Register as a DRep, delegate your vote, vote on actions and submit proposals with TxBuilder.
Overview
Governance uses certificates, votes and proposals, passed as parts to builder.build(). A DRep (delegated representative) votes on behalf of the stake delegated to it. Use this page to act as a DRep, vote or propose.
A certificate changes what the chain records, such as a DRep's registration or a vote delegation. Every certificate is in Certificates.
The DRep and proposal deposits are protocol parameters that Mesh's Protocol type does not carry, so the builder takes them from its deposits option, or from deposit on a part. Without them the build throws MISSING_PARAMETER (see Deposits).
Examples stop at build(): call built.sign() and built.submit() as in Transaction Basics. They use wallet and provider from there, and these names, which your application defines:
builder- aTxBuilderwith the deposits of your network:new TxBuilder({ network: "preprod", provider, deposits: { drepDeposit: 500_000_000n, govActionDeposit: 100_000_000_000n } })rewardAddress- your stake address (stake_test1...on a test network,stake1...on mainnet)drepId- a DRep id (drep1...)anchor-{ url, dataHash }, where a metadata or rationale file is published.hashDrepAnchor(json)makes the hash.actionTxHash- the transaction hash of a governance action
| Task | Part | Signed by |
|---|---|---|
| Register, update or retire a DRep | certificate.drepRegistration, drepUpdate, drepDeregistration | the DRep key |
| Delegate your vote | certificate.voteDelegation | the stake key |
| Authorise a hot key or resign from the committee | certificate.committeeHotAuth, committeeColdResign | the cold key |
| Vote on an action | vote | the voter's key |
| Submit a proposal | proposal.info, proposal.treasuryWithdrawals and others | the payer |
Manage a DRep
- Register:
certificate.drepRegistration.anchoris optional. - Update:
certificate.drepUpdate, with theanchorof the changed file. Leaveanchorout to clear it. - Retire:
certificate.drepDeregistration, which refunds the deposit. - Deposit:
drepDepositfrom the builder, ordepositandrefundon the part. See Deposits. - Signing: the DRep key signs, and a browser wallet must be connected with the CIP-95 extension. See Who Signs.
import { certificate } from "@meshsdk/core";
const built = await builder.build(
certificate.drepRegistration({ drep: drepId, anchor }),
{ payer: wallet },
);Delegate Your Vote
A registered stake key delegates its voting power with certificate.voteDelegation. drep is a DRep id, "alwaysAbstain" or "alwaysNoConfidence". To delegate to a pool and a DRep together, use certificate.stakeAndVoteDelegation. The combined builders are in Delegation.
import { certificate } from "@meshsdk/core";
const built = await builder.build(
certificate.voteDelegation({ stake: rewardAddress, drep: drepId }),
{ payer: wallet },
);Vote on an Action
All votes of one voter go in one vote part. vote is "yes", "no" or "abstain", and anchor points to your rationale. A voter can also be { pool } or { committee }. A script DRep adds a witness.
import { vote } from "@meshsdk/core";
const built = await builder.build(
vote({
voter: { drep: drepId },
votes: [
{ action: { txHash: actionTxHash, index: 0 }, vote: "yes", anchor },
],
}),
{ payer: wallet },
);Submit a Proposal
proposal.info is a governance action with no effect on the chain, used as a poll. The deposit is govActionDeposit, or deposit on the part. It is paid from the payer's UTxOs and goes back to rewardAccount when the action ends.
import { proposal } from "@meshsdk/core";
const built = await builder.build(
proposal.info({ rewardAccount: rewardAddress, anchor }),
{ payer: wallet },
);Propose Other Actions
Each action takes rewardAccount and anchor, plus its own fields:
treasuryWithdrawals-withdrawals, lovelace by receiving reward addressparameterChange-updateshardForkInitiation-protocolVersionupdateCommittee-quorum, andaddandremovefor membersnewConstitution-constitutionnoConfidence- nothing more
parameterChange and treasuryWithdrawals run the constitution's guardrail script. Leave guardrail out and the build adds it: the guardrail your provider's fetchConstitution reports, or, when the provider cannot say, the one of mainnet, preprod and preview, the same script on all three. On another network it is added only when the provider reports it. The guardrail is a Plutus script, so the build also puts up collateral and evaluates it. A constitution that names a guardrail Mesh does not hold is UNRESOLVED: pass that script as guardrail. guardrail: null builds the proposal without one. Every action except info and treasuryWithdrawals takes previous: { txHash, index }, the action it follows.
import { proposal } from "@meshsdk/core";
const built = await builder.build(
proposal.treasuryWithdrawals({
rewardAccount: rewardAddress,
anchor,
withdrawals: { [rewardAddress]: 50_000_000_000n },
}),
{ payer: wallet },
);Related
- Certificates - every certificate, its deposit and its signer
- Staking Transactions - register a stake key, delegate and withdraw
- Transaction Basics - the builder, the payer and signing
- Signing and Submitting - sign with a DRep key or several signers
- Options - the
depositsoption and the other options - Migrating to TxBuilder - move from the
MeshTxBuilderchain - Package README - every part, option and error