SDK Installation
Install the CredDAO SDK and its dependencies.
Requirements
| Package | Version |
|---|---|
| Node.js | 20+ |
| @solana/web3.js | ^1.95+ |
| @coral-xyz/anchor | ^0.30+ |
Install Package
npm install @creddao/sdk @solana/web3.js @coral-xyz/anchorPeer Dependencies
The SDK requires these peer dependencies:
{
"peerDependencies": {
"@solana/web3.js": "^1.95.0",
"@coral-xyz/anchor": "^0.30.1",
"bn.js": "^5.2.1"
}
}TypeScript Configuration
Ensure your tsconfig.json includes:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
}
}Environment Variables
Create a .env file:
SOLANA_RPC_URL=https://api.devnet.solana.com
CREDDAO_PROGRAM_ID=CreDDAo111111111111111111111111111111111111
FAIRSCORE_ORACLE_ID=Faire11111111111111111111111111111111111111Basic Setup
import { CredDAOClient } from '@creddao/sdk';
import { Connection, clusterApiUrl, PublicKey } from '@solana/web3.js';
import { AnchorProvider } from '@coral-xyz/anchor';
// Network configuration
const RPC_URL = process.env.SOLANA_RPC_URL || clusterApiUrl('devnet');
const PROGRAM_ID = new PublicKey(process.env.CREDDAO_PROGRAM_ID!);
// Create connection
const connection = new Connection(RPC_URL, 'confirmed');
// Provider setup (with wallet adapter)
const provider = new AnchorProvider(connection, wallet, {
commitment: 'confirmed',
});
// Initialize client
const client = new CredDAOClient({
provider,
programId: PROGRAM_ID,
});Using with Wallet Adapters
React
import { useWallet, useConnection } from '@solana/wallet-adapter-react';
import { AnchorProvider } from '@coral-xyz/anchor';
import { CredDAOClient } from '@creddao/sdk';
function useCredDAO() {
const { connection } = useConnection();
const wallet = useWallet();
const client = useMemo(() => {
if (!wallet.publicKey || !wallet.signTransaction) return null;
const provider = new AnchorProvider(connection, wallet as any, {
commitment: 'confirmed',
});
return new CredDAOClient({
provider,
programId: new PublicKey('CreDDAo111111111111111111111111111111111111'),
});
}, [connection, wallet]);
return client;
}Node.js
import { Connection, Keypair } from '@solana/web3.js';
import { AnchorProvider, Wallet } from '@coral-xyz/anchor';
import { CredDAOClient } from '@creddao/sdk';
// Load keypair from file
const keypair = Keypair.fromSecretKey(
Buffer.from(JSON.parse(fs.readFileSync('keypair.json', 'utf-8')))
);
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
const wallet = new Wallet(keypair);
const provider = new AnchorProvider(connection, wallet, {});
const client = new CredDAOClient({
provider,
programId: new PublicKey('CreDDAo111111111111111111111111111111111111'),
});Verify Installation
// Test connection
const slot = await client.connection.getSlot();
console.log('Connected! Current slot:', slot);
// Test program
const config = await client.getDaoConfig();
console.log('DAO Config:', config);Common Issues
Module not found errors
Ensure all peer dependencies are installed:
npm install @solana/web3.js @coral-xyz/anchor bn.jsType errors with BN
Install type definitions:
npm install -D @types/bn.jsWallet adapter issues
Ensure the wallet is connected before creating the client:
if (!wallet.connected) {
await wallet.connect();
}