Create Schema

Creates a new schema that defines the structure for attestations

Create Schema

Creates a new schema that defines the structure and validation rules for attestations. This instruction allows credential authorities to create schemas that specify what fields an attestation should contain and how they should be formatted.

Parameters

ParameterTypeDescription
payerSignerThe account that will pay for the transaction
authoritySignerThe authority of the credential
credentialPublicKey | PdaThe credential account this schema will be associated with
schemaPublicKey | PdaThe schema account to create
systemProgramPublicKey | PdaThe System Program account (defaults to '11111111111111111111111111111111')
namestringThe name of the schema
descriptionstringA detailed description of the schema's purpose
layoutReadonlyUint8ArrayThe binary layout definition of the schema
fieldNamesstring[]The names of fields in the schema

Returns

Returns a TransactionBuilder that can be used to build and send the transaction.

Example

import { getCreateSchemaInstruction } from "sas-lib";

const transaction = getCreateSchemaInstruction({
    payer: payerSigner,
    authority: authoritySigner,
    credential: credentialPublicKey,
    schema: schemaPublicKey,
    systemProgram: systemProgramPublicKey,
    name: "Identity Verification",
    description: "Schema for verifying user identity information",
    layout: schemaLayoutBytes,
    fieldNames: ["fullName", "dateOfBirth", "nationality"]
});

// Send the transaction
await transaction.sendAndConfirm();

Important Notes

  • The payer must be a signer of the transaction
  • The authority must be a signer of the transaction and must be the authority of the credential
  • The schema account must be writable
  • The credential account must be readable
  • This operation requires the System Program for rent exemption calculations
  • The schema name should be descriptive and unique within the credential
  • The description should provide clear information about the schema's purpose and usage
  • The layout must be a valid binary format that defines the structure of attestation data
  • The fieldNames array must match the fields defined in the layout
  • The schema can be paused later if needed
  • The schema can be versioned to support evolution of the data structure
  • All attestations created under this schema must conform to its structure