Developer console

SDK

TypeScript SDK

Verify trust scores directly from Solana

The CredLayer SDK provides typed clients for reading AI-generated trust scores from the Solana blockchain. Query attestations without relying on centralized APIs.

On-Chain Verification

Read trust scores directly from Solana Program Derived Addresses (PDAs) without third-party dependencies.

Simple Integration

Two methods: getScore() for full data and isApproved() for quick access control.

TypeScript Native

Fully typed interfaces for CredLayerScore with IntelliSense support in VS Code and other editors.

Code Examples

Installation

npm install @credlayer/sdk @solana/web3.js

Initialize Client

import { CredLayerClient } from '@credlayer/sdk';

// Initialize with default Devnet settings
const credlayer = new CredLayerClient();

// Or override with custom settings
const credlayer = new CredLayerClient(
  'https://api.mainnet-beta.solana.com', // Custom RPC
  'YOUR_CREDENTIAL_PDA',
  'YOUR_SCHEMA_PDA'
);

Fast Verification (Access Control)

// Check if wallet meets minimum trust score threshold
const isSafe = await credlayer.isApproved(walletAddress, 800);

if (isSafe) {
  console.log("✅ Access Granted");
  // Grant loan, allow swap, enable feature, etc.
} else {
  console.log("🚫 Access Denied");
  // Block access or request additional verification
}

Fetch Full Score Data

// Get complete trust score data for UI display
const scoreData = await credlayer.getScore(walletAddress);

if (!scoreData) {
  console.log("No attestation found");
  return;
}

if (!scoreData.isValid) {
  console.log("⚠️ Score was revoked");
  return;
}

console.log(`Trust Score: ${scoreData.trustScore}`); // e.g., 850
console.log(`Risk Level: ${scoreData.riskLevel}`);   // e.g., "LOW"

React Component Example

import { CredLayerClient } from '@credlayer/sdk';
import { useState, useEffect } from 'react';

function TrustScoreDisplay({ walletAddress }: { walletAddress: string }) {
  const [score, setScore] = useState<number | null>(null);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    const fetchScore = async () => {
      const client = new CredLayerClient();
      const data = await client.getScore(walletAddress);
      setScore(data?.trustScore ?? null);
      setLoading(false);
    };
    fetchScore();
  }, [walletAddress]);

  if (loading) return <div>Loading...</div>;
  if (!score) return <div>No score found</div>;

  return (
    <div>
      <h3>Trust Score: {score}</h3>
      <p>Status: {score >= 800 ? 'Verified' : 'Below threshold'}</p>
    </div>
  );
}

API Reference

CredLayerClient

Main client class for interacting with on-chain trust scores.

constructor(rpcUrl?, credentialPdaStr?, schemaPdaStr?)

Initialize the client. All parameters are optional and default to Devnet settings.

getScore(walletAddress: string | PublicKey): Promise<CredLayerScore | null>

Fetches complete trust score data including trustScore, riskLevel, and isValid flag.

isApproved(walletAddress: string, minimumScore?: number): Promise<boolean>

Returns true if score exists, is valid (not revoked), and meets minimumScore (defaults to 800).

CredLayerScore

Interface for trust score data returned by getScore().

trustScore: numberAI-calculated score (300-850 range)
riskLevel: stringCategorical risk: "LOW", "MEDIUM", "HIGH"
isValid: booleanFalse if attestation was revoked

Common Use Cases

DeFi Protocols

Gate lending pools, adjust interest rates, or require additional collateral based on borrower trust scores.

NFT Marketplaces

Verify buyer/seller reputation before high-value trades or enable trusted-only marketplace sections.

Gaming & Social

Prevent sybil attacks, match players with similar reputation levels, or unlock features for verified users.

DAO Governance

Weight voting power by trust score or require minimum reputation thresholds for proposal creation.

Ready to integrate?

Check out the full documentation and API reference for advanced usage.

View documentation