DocumentationsdkGovernance Module

Governance Module

Methods for interacting with CredDAO governance features.

createProposal

Create a new governance proposal.

async createProposal(params: CreateProposalParams): Promise<TransactionResult>

Parameters

interface CreateProposalParams {
  proposalType: ProposalType;
  title: string;
  description: string;
}

Type of proposal: Standard, Expedited, or Emergency.

Short, descriptive title for the proposal.

Detailed description and rationale.

Returns

interface TransactionResult {
  signature: string;
  proposalAddress: PublicKey;
}

Example

import { ProposalType } from '@creddao/sdk';
 
const result = await client.createProposal({
  proposalType: ProposalType.Standard,
  title: 'Treasury Allocation for Development',
  description: `
    ## Summary
    Allocate 5% of treasury to development fund.
    
    ## Rationale
    - Fund community projects
    - Increase ecosystem growth
    - Support core development
  `,
});
 
console.log('Proposal created:', result.proposalAddress.toBase58());

Errors

ErrorCause
InsufficientReputationTierMember tier too low for proposal type
InsufficientActiveDaysLess than 30 active days

castVote

Cast a vote on an active proposal.

async castVote(params: CastVoteParams): Promise<TransactionResult>

Parameters

interface CastVoteParams {
  proposalAddress: PublicKey;
  vote: VoteType;
}

Public key of the proposal to vote on.

Vote type: For (0), Against (1), or Abstain (2).

Returns

interface TransactionResult {
  signature: string;
  votingPower: number;
}

Example

import { VoteType } from '@creddao/sdk';
 
const result = await client.castVote({
  proposalAddress: new PublicKey('...'),
  vote: VoteType.For,
});
 
console.log('Voted with power:', result.votingPower);

getProposal

Fetch a single proposal.

async getProposal(proposalAddress: PublicKey): Promise<ProposalAccount>

Example

const proposal = await client.getProposal(proposalAddress);
 
console.log('Title:', proposal.title);
console.log('State:', proposal.state);
console.log('For:', proposal.forVotes.toNumber());
console.log('Against:', proposal.againstVotes.toNumber());
console.log('Voting ends:', new Date(proposal.votingEnd.toNumber() * 1000));

getActiveProposals

Fetch all proposals in voting state.

async getActiveProposals(): Promise<ProposalAccount[]>

Example

const proposals = await client.getActiveProposals();
 
for (const p of proposals) {
  const remaining = p.votingEnd.toNumber() - Math.floor(Date.now() / 1000);
  const hours = Math.floor(remaining / 3600);
  
  console.log(`${p.title} - ${hours}h remaining`);
}

finalizeProposal

Finalize a proposal after voting ends.

async finalizeProposal(proposalAddress: PublicKey): Promise<TransactionResult>

This can be called by anyone after the voting period ends.

Example

const proposal = await client.getProposal(address);
 
if (Date.now() / 1000 >= proposal.votingEnd.toNumber()) {
  await client.finalizeProposal(address);
  console.log('Proposal finalized');
}

executeProposal

Execute a succeeded proposal after time-lock.

async executeProposal(proposalAddress: PublicKey): Promise<TransactionResult>

Example

const proposal = await client.getProposal(address);
 
if (
  proposal.state === 'succeeded' &&
  Date.now() / 1000 >= proposal.timeLockExpiry.toNumber()
) {
  await client.executeProposal(address);
  console.log('Proposal executed!');
}

getVoteRecords

Get all vote records for a wallet.

async getVoteRecords(wallet: PublicKey): Promise<VoteRecordAccount[]>

Example

const votes = await client.getVoteRecords(wallet.publicKey);
 
votes.forEach(v => {
  console.log({
    proposal: v.proposal.toBase58(),
    vote: ['For', 'Against', 'Abstain'][v.vote],
    power: v.votingPower.toNumber(),
    date: new Date(v.timestamp.toNumber() * 1000),
  });
});

getDaoConfig

Fetch the DAO configuration.

async getDaoConfig(): Promise<DaoConfig>

Example

const config = await client.getDaoConfig();
 
console.log('Quorum:', config.quorumPercentage + '%');
console.log('Voting Period:', config.votingPeriod / 3600, 'hours');
console.log('Min Active Days:', config.minActiveDays);

Proposal Lifecycle

// 1. Create proposal
const { proposalAddress } = await client.createProposal({
  proposalType: ProposalType.Standard,
  title: 'My Proposal',
  description: 'Description...',
});
 
// 2. Wait for voting period
const proposal = await client.getProposal(proposalAddress);
 
// 3. Cast votes
await client.castVote({
  proposalAddress,
  vote: VoteType.For,
});
 
// 4. Finalize after voting ends
await client.finalizeProposal(proposalAddress);
 
// 5. Execute after time-lock
await client.executeProposal(proposalAddress);