Skip to content

Create Class

Creates a new class that defines a template for records that can be created under it.

Parameters

ParameterTypeDescription
authoritySignerThe authority that will have control over the class
classPublicKey | PdaThe new class account to be initialized
systemProgram?PublicKey | PdaOptional System Program account
isPermissionedbooleanWhether records under this class require special permissions
isFrozenbooleanWhether the class is initially frozen
namestringThe name of the class
metadatastringSerialized metadata for the class

Returns

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

Example

import { createClass } from "srs-lib";
 
const transaction = createClass(context, {
    authority: authority,
    class: classPublicKey,
    systemProgram: systemProgramPublicKey,
    isPermissioned: true,
    isFrozen: false,
    name: "Example Class",
    metadata: JSON.stringify({
        description: "This is an example class",
        schema: {
            title: { type: "string" },
            description: { type: "string" }
        }
    })
});
 
// Send the transaction
await transaction.sendAndConfirm();

Important Notes

  • The authority will have control over all records created under this class
  • The class name should be unique within your application
  • The metadata should contain a valid schema that defines the structure of records
  • Once created, the class's schema cannot be modified
  • Records created under this class must conform to the defined schema
  • If isPermissioned is true, only the class authority can create records

Related