Skip to main content

What is a Schema?

A schema defines the structure of attestation data. All attestations reference a schema.

Creating a Schema

await client.createSchema({
  definition: 'struct KYC { bool verified; string level; u64 timestamp; }',
  revocable: true,
  resolver: undefined, // Optional: validation contract
  options: { signer }
});

Schema Syntax

struct Name { type field; type field; ... }

Supported Types

TypeDescriptionExample
boolBooleantrue, false
stringText"hello"
u32Unsigned 32-bit42
u64Unsigned 64-bit1234567890
i32Signed 32-bit-42
i64Signed 64-bit-1234567890
bytesBinary data0x1234...

Example Schemas

KYC Verification

struct KYC { bool verified; string level; string provider; u64 expiry; }

Professional Credential

struct Credential { string title; string issuer; u64 issuedAt; u64 expiresAt; }

Reputation Score

struct Reputation { u32 score; string category; u64 updatedAt; }

Generating Schema UID

Schema UIDs are deterministic based on definition + authority:
const schemaUid = client.generateSchemaUid({
  definition: 'struct KYC { bool verified; string level; }',
  authority: keypair.publicKey(),
  resolver: undefined
});

Querying Schemas

// By UID
const schema = await client.getSchema(schemaUid);

// By wallet (schemas you created)
const { schemas } = await client.fetchSchemasByWallet({
  walletAddress: keypair.publicKey(),
  limit: 50
});

// Latest schemas
const latest = await client.fetchSchemas(100);

Best Practices

  1. Keep it simple - Only include necessary fields
  2. Use appropriate types - u64 for timestamps, bool for flags
  3. Consider revocability - Set revocable: true for credentials that may need invalidation
  4. Version schemas - Include version in name: struct KYC_v2 { ... }