Skip to content

Create Record

Creates a new record under a specified class with the provided data and metadata.

Parameters

ParameterTypeDescription
ownerSignerThe owner of the new record
classPublicKey | PdaThe class account under which the record will be created
recordPublicKey | PdaThe record account to be created
systemProgram?PublicKey | PdaOptional System Program account
authority?SignerOptional authority required for permissioned classes
expirationnumber | bigintUnix timestamp when the record expires (0 for no expiration)
namestringThe name of the record
datastringSerialized data for the record

Returns

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

Example

import { createRecord } from "srs-lib";
 
const transaction = createRecord(context, {
    owner: owner,
    class: classPublicKey,
    record: recordPublicKey,
    systemProgram: systemProgramPublicKey,
    authority: authority, // Required if class is permissioned
    expiration: 0, // No expiration
    name: "Example Record",
    data: JSON.stringify({
        title: "My Record",
        description: "This is an example record",
        // Additional data conforming to the class schema
    })
});
 
// Send the transaction
await transaction.sendAndConfirm();

Important Notes

  • The record's data must conform to the schema defined in its class
  • For permissioned classes, the authority must be provided and must be the class authority
  • The record owner will have control over the record and can update or burn it
  • The expiration timestamp is optional (use 0 for no expiration)
  • The record name should be unique within its class
  • The data must be properly serialized according to the class schema

Related