Skip to content

doesSchemaIdExists

doesSchemaIdExists(schemaUri): Promise<boolean>

Asynchronously checks if a schema with the given URI exists on-chain.

This function interacts with the blockchain using the configured API service to verify the existence of a schema by querying the schema storage. It converts the provided schema URI into an identifier, which is used to fetch the corresponding schema entry. If an entry exists, the function returns true; otherwise, it returns false.

schemaUri: `schema:cord:${string}`

The URI of the schema to be checked. This URI serves as the reference to uniquely identify the schema on-chain.

Promise<boolean>

  • A promise that resolves to:
  • true if the schema exists on-chain.
  • false if the schema does not exist or the query returns None.
const schemaUri = 'cord:schema:123456789';
doesSchemaIdExists(schemaUri)
.then(exists => {
if (exists) {
console.log('Schema exists on-chain.');
} else {
console.log('Schema not found.');
}
})
.catch(error => console.error('Error checking schema existence:', error));
  1. Fetching the API: The function retrieves the blockchain API instance using the ConfigService.
  2. Converting URI to Identifier: The URI is converted into an identifier using uriToIdentifier.
  3. Querying Blockchain Storage: It queries the schemas storage in schema with the identifier.
  4. Checking Existence: If the query returns None, the schema does not exist; otherwise, it exists.
  • Any error encountered while querying the blockchain API will be propagated as a rejected promise.
  • ConfigService: Retrieves the blockchain API instance.
  • uriToIdentifier: Converts schema URI into a blockchain-compatible identifier.

schema/src/Schema.chain.ts:132