Client Reference
The main client class for interacting with CredDAO.
Constructor
const client = new CredDAOClient(options: CredDAOClientOptions);Configuration options for the client.
Options
interface CredDAOClientOptions {
provider: AnchorProvider; // Anchor provider with wallet
programId: PublicKey; // CredDAO program ID
oracleProgramId?: PublicKey; // FairScore oracle program ID
skipPreflight?: boolean; // Skip preflight checks
}Properties
program
program: ProgramThe Anchor Program instance for CredDAO.
provider
provider: AnchorProviderThe configured Anchor provider.
connection
connection: ConnectionThe Solana connection instance.
Methods
getDaoConfig
Fetch the DAO configuration account.
async getDaoConfig(): Promise<DaoConfig>Returns: DaoConfig object
Example:
const config = await client.getDaoConfig();
console.log('Quorum:', config.quorumPercentage + '%');
console.log('Voting Period:', config.votingPeriod + ' seconds');getMemberProfile
Fetch a member’s profile.
async getMemberProfile(wallet: PublicKey): Promise<MemberProfile>Public key of the member to fetch.
Returns: MemberProfile object
Example:
const profile = await client.getMemberProfile(wallet.publicKey);
console.log('Tier:', profile.tier);
console.log('FairScore:', profile.fairscore.toNumber());
console.log('Active Days:', profile.activeDays.toNumber());registerMember
Register a new member.
async registerMember(params: RegisterMemberParams): Promise<TransactionResult>Registration parameters.
interface RegisterMemberParams {
fairscore: number;
}Returns: Transaction signature and member account address
Example:
const result = await client.registerMember({ fairscore: 50 });
console.log('Registered:', result.signature);calculateVotingPower
Calculate voting power for a given token balance and FairScore.
calculateVotingPower(
tokenBalance: number,
fairscore: number
): VotingPowerResultToken balance of the voter.
FairScore of the voter (0-100).
Returns: VotingPowerResult object
interface VotingPowerResult {
quadraticBase: number;
reputationMultiplier: number;
totalPower: number;
}Example:
const power = client.calculateVotingPower(10000, 78);
console.log('Voting Power:', power.totalPower);getProposal
Fetch a proposal by its address.
async getProposal(proposalAddress: PublicKey): Promise<ProposalAccount>Public key of the proposal account.
Returns: ProposalAccount object
getActiveProposals
Fetch all active proposals.
async getActiveProposals(): Promise<ProposalAccount[]>Returns: Array of active proposals
Example:
const proposals = await client.getActiveProposals();
proposals.forEach(p => {
console.log(p.title, '-', p.state);
});createProposal
Create a new governance proposal.
async createProposal(params: CreateProposalParams): Promise<TransactionResult>Proposal parameters.
interface CreateProposalParams {
proposalType: ProposalType;
title: string;
description: string;
}Example:
const result = await client.createProposal({
proposalType: ProposalType.Standard,
title: 'Treasury Allocation',
description: 'Allocate funds for development...',
});castVote
Cast a vote on a proposal.
async castVote(params: CastVoteParams): Promise<TransactionResult>Vote parameters.
interface CastVoteParams {
proposalAddress: PublicKey;
vote: VoteType;
}Example:
await client.castVote({
proposalAddress: proposal.publicKey,
vote: VoteType.For,
});delegate
Delegate voting power to another member.
async delegate(params: DelegateParams): Promise<TransactionResult>Delegation parameters.
interface DelegateParams {
delegate: PublicKey;
}Example:
await client.delegate({
delegate: new PublicKey('7xKXtg2C...'),
});revokeDelegation
Revoke active delegation.
async revokeDelegation(): Promise<TransactionResult>getDelegationRecord
Get the delegation record for a wallet.
async getDelegationRecord(wallet: PublicKey): Promise<DelegationRecord>getVoteRecords
Get all vote records for a wallet.
async getVoteRecords(wallet: PublicKey): Promise<VoteRecordAccount[]>getTopDelegates
Get top delegates sorted by efficiency.
async getTopDelegates(options?: {
sortBy?: 'efficiency' | 'delegators' | 'votingPower';
limit?: number;
}): Promise<DelegateInfo[]>Types
TransactionResult
interface TransactionResult {
signature: string;
proposalAddress?: PublicKey;
votingPower?: number;
efficiency?: number;
}