Skip to main content

Factory Methods

The SDK uses factory methods to create blockchain-specific instances. Each blockchain requires separate initialization.

AttestSDK.initializeStellar()

Creates and initializes a Stellar SDK instance. Parameters:
ParameterTypeRequiredDescription
configStellarConfigStellar network configuration
Returns: Promise<StellarAttestSDK>
import { AttestSDK } from '@attestprotocol/sdk';

const stellarSDK = await AttestSDK.initializeStellar({
  secretKeyOrCustomSigner: 'SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  publicKey: 'GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  url: 'https://soroban-testnet.stellar.org'
});
Configuration Interface:
interface StellarConfig extends ChainConfig {
  secretKeyOrCustomSigner: string | StellarCustomSigner;
  publicKey: string;
  url?: string;
}

AttestSDK.initializeSolana()

Creates and initializes a Solana SDK instance. Parameters:
ParameterTypeRequiredDescription
configSolanaConfigSolana network configuration
Returns: Promise<SolanaAttestSDK>
import { AttestSDK } from '@attestprotocol/sdk';

const solanaSDK = await AttestSDK.initializeSolana({
  walletOrSecretKey: [1, 2, 3, /* ...64 numbers */],
  programId: 'BMr9aui54YuxtpBzWXiFNmnr2iH6etRu7rMFJnKxjtpY',
  url: 'https://api.devnet.solana.com'
});
Configuration Interface:
interface SolanaConfig extends ChainConfig {
  walletOrSecretKey: number[] | anchor.Wallet;
  programId?: string;
  url?: string;
}

Response Pattern

All SDK methods return a consistent response wrapper for unified error handling across chains.
type AttestSDKResponse<T> = 
  | { data: T; error?: undefined }
  | { data?: undefined; error: any }
Usage Pattern:
const result = await sdk.fetchAuthority();

if (result.error) {
  console.error('Operation failed:', result.error);
  return;
}

// Use result.data safely
console.log('Authority:', result.data);

Authority Methods

fetchAuthority()

Retrieves authority information for the current wallet. Parameters: None Returns:
  • Stellar: AttestSDKResponse<StellarFetchAuthorityResult | null>
  • Solana: AttestSDKResponse<SolanaFetchAuthorityResult>
Chain Support:
ChainReturn TypeDescription
Stellar{ address: string, metadata: string }Authority address and metadata
Solana{ authority: PublicKey, isVerified: boolean, firstDeployment: BN }Authority details with verification status
const result = await stellarSDK.fetchAuthority();

if (result.data) {
  console.log('Authority address:', result.data.address);
  console.log('Metadata:', result.data.metadata);
}

registerAuthority()

Registers the current wallet as an authority. Parameters: None Returns:
  • Stellar: AttestSDKResponse<string> (transaction hash)
  • Solana: AttestSDKResponse<anchor.web3.PublicKey> (authority PDA)
const result = await stellarSDK.registerAuthority();

if (result.data) {
  console.log('Registration TX:', result.data);
}

Schema Methods

createSchema()

Creates a new attestation schema.
Schema names must be unique within each blockchain. Attempting to create a duplicate will fail.
Parameters:
  • Stellar
  • Solana
ParameterTypeRequiredDescription
schemaNamestringUnique schema identifier
schemaContentstringSchema definition
resolverAddressstringResolver contract address
revocablebooleanRevocation capability (default: true)
Returns:
  • Stellar: AttestSDKResponse<StellarCreateSchemaResult>
  • Solana: AttestSDKResponse<anchor.web3.PublicKey>
const result = await stellarSDK.createSchema({
  schemaName: 'kyc-verification',
  schemaContent: 'verified:bool,level:string,score:uint',
  revocable: true
});

if (result.data) {
  console.log('Schema UID:', result.data.schemaUID);
  console.log('Schema name:', result.data.schemaName);
}

fetchSchema()

Retrieves schema by UID. Parameters:
ParameterTypeRequiredDescription
schemaUIDstring (Stellar) / PublicKey (Solana)Schema identifier
Returns:
  • Stellar: AttestSDKResponse<StellarFetchSchemaResult | null>
  • Solana: AttestSDKResponse<SolanaFetchSchemaResult | null>
interface StellarFetchSchemaResult {
  uid: string;
  definition: string;
  authority: string;
  revocable: boolean;
  resolver: string | null;
}

Attestation Methods

attest()

Creates a new attestation.
Attestation data must match the schema definition format. Mismatched data will cause validation errors.
Parameters:
  • Stellar
  • Solana
ParameterTypeRequiredDescription
schemaUIDstring64-character hex string
subjectstringStellar address
valuestringAttestation data
referencestringReference string
const result = await stellarSDK.attest({
  schemaUID: 'abc123...',
  subject: 'GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  value: 'verified:true,level:enhanced,score:95',
  reference: 'kyc-2024-001'
});

if (result.data) {
  console.log('Attestation TX:', result.data);
}

fetchAttestation()

Retrieves attestation data. Parameters:
  • Stellar
  • Solana
ParameterTypeRequiredDescription
schemaUIDstring64-character hex string
subjectstringStellar address
referencestringReference string
const result = await stellarSDK.fetchAttestation({
  schemaUID: 'abc123...',
  subject: 'GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  reference: 'kyc-2024-001'
});

if (result.data && !result.data.revoked) {
  console.log('Attestation value:', result.data.value);
}

revokeAttestation()

Revokes an existing attestation.
Only the original attester can revoke an attestation. The attestation must be revocable.
Parameters:
  • Stellar
  • Solana
ParameterTypeRequiredDescription
schemaUIDstring64-character hex string
subjectstringStellar address
referencestringReference string

Utility Methods

getWalletBalance()

This method is only available on Solana. Use native Stellar SDK methods for Stellar balance queries.
Returns wallet balance and address information. Parameters: None Returns: AttestSDKResponse<{ balance: number; address: PublicKey }>
const result = await solanaSDK.getWalletBalance();

if (result.data) {
  console.log('Address:', result.data.address.toBase58());
  console.log('Balance:', result.data.balance, 'SOL');
}

initialize()

This method is only available on Stellar and requires admin privileges.
Initializes the protocol contract. Parameters: None Returns: AttestSDKResponse<void>
const result = await stellarSDK.initialize();

if (!result.error) {
  console.log('Protocol initialized successfully');
}

Chain Support Matrix

Not all methods are available on all chains. Check this matrix before implementation.
MethodStellarSolanaNotes
fetchAuthority()Different return structures
registerAuthority()Returns string vs PublicKey
createSchema()Solana supports levy config
fetchSchema()Different identifier types
attest()Different parameter sets
fetchAttestation()Different query methods
revokeAttestation()Similar functionality
getWalletBalance()Solana only
initialize()Stellar only
initializeAuthority()Stellar only

Contract Information

Default Addresses

Stellar Testnet

Protocol Contract: CBPL7XR7NNPTNSIIFWQMWLSCX3B3MM36UYX4TW3QXJKTIEA6KDLRYAQPAuthority Contract: CDQREK6BTPEVD4O56XR6TKLEEMNYTRJUG466J2ERNE5POIEKN2N6O7ELRPC Endpoint: https://soroban-testnet.stellar.org

Solana Devnet

Program ID: BMr9aui54YuxtpBzWXiFNmnr2iH6etRu7rMFJnKxjtpYRPC Endpoint: https://api.devnet.solana.com

TypeScript Imports

Import the SDK components you need:
// Main SDK factory
import { AttestSDK } from '@attestprotocol/sdk';

// Configuration interfaces
import { 
  StellarConfig, 
  SolanaConfig 
} from '@attestprotocol/sdk';

// Chain-specific SDK classes
import { 
  StellarAttestSDK, 
  SolanaAttestSDK 
} from '@attestprotocol/sdk';

// Response wrapper type
import { AttestSDKResponse } from '@attestprotocol/sdk';

// Result interfaces
import {
  StellarFetchAuthorityResult,
  SolanaFetchAuthorityResult,
  StellarFetchSchemaResult,
  SolanaFetchSchemaResult,
  StellarFetchAttestationResult,
  SolanaFetchAttestationResult
} from '@attestprotocol/sdk';

Next Steps