SDK Overview
The CredDAO SDK provides a TypeScript library for interacting with CredDAO smart contracts on Solana.
Installation
npm install @creddao/sdk @solana/web3.js @coral-xyz/anchorQuick Start
import { CredDAOClient } from '@creddao/sdk';
import { Connection, clusterApiUrl } from '@solana/web3.js';
import { AnchorProvider, Wallet } from '@coral-xyz/anchor';
import { PublicKey } from '@solana/web3.js';
// Setup connection
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
// Create provider with wallet
const provider = new AnchorProvider(connection, wallet, {
commitment: 'confirmed',
});
// Initialize client
const client = new CredDAOClient({
provider,
programId: new PublicKey('CreDDAo111111111111111111111111111111111111'),
});Modules
The SDK is organized into modules:
| Module | Description |
|---|---|
CredDAOClient | Main client for all interactions |
Governance | Proposal and voting operations |
Delegation | Delegation management |
FairScoreOracle | Score queries and updates |
Exports
// Client
export { CredDAOClient } from './CredDAOClient';
// Modules
export { Governance } from './Governance';
export { Delegation } from './Delegation';
export { FairScoreOracle } from './FairScoreOracle';
// Types
export * from './types';
// Constants
export * from './constants';
// Utilities
export * from './utils';Types
Enums
enum ReputationTier {
Unscored = 'unscored',
Bronze = 'bronze',
Silver = 'silver',
Gold = 'gold',
Platinum = 'platinum',
}
enum ProposalType {
Standard = 'standard',
Expedited = 'expedited',
Emergency = 'emergency',
}
enum ProposalState {
Draft = 'draft',
Voting = 'voting',
Succeeded = 'succeeded',
Defeated = 'defeated',
Executed = 'executed',
Cancelled = 'cancelled',
}
enum VoteType {
For = 0,
Against = 1,
Abstain = 2,
}Interfaces
interface MemberProfile {
wallet: PublicKey;
fairscore: BN;
tier: ReputationTier;
activeDays: BN;
proposalsSubmitted: number;
proposalsVoted: number;
delegateTo: PublicKey | null;
badges: number;
}
interface ProposalAccount {
daoConfig: PublicKey;
proposer: PublicKey;
proposalType: ProposalType;
state: ProposalState;
forVotes: BN;
againstVotes: BN;
votingEnd: BN;
timeLockExpiry: BN;
}
interface VotingPowerResult {
quadraticBase: number;
reputationMultiplier: number;
totalPower: number;
}Configuration Options
interface CredDAOClientOptions {
provider: AnchorProvider;
programId: PublicKey;
oracleProgramId?: PublicKey;
skipPreflight?: boolean;
}Error Handling
try {
await client.createProposal({ ... });
} catch (error) {
if (error.message.includes('InsufficientReputationTier')) {
console.log('Your tier is too low for this action');
} else if (error.message.includes('InsufficientActiveDays')) {
console.log('You need more active days');
}
}Next Steps
Client Reference
Full API reference for CredDAOClient.
Governance Module
Proposals, voting, and execution.
Delegation Module
Manage voting delegation.
FairScore Module
Query and manage reputation scores.