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
.
Parameters:
Parameters
• 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.
Returns:
Returns
Promise
<boolean
>
- A promise that resolves to:
true
if the schema exists on-chain.false
if the schema does not exist or the query returnsNone
.
Example Usage:
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));
Internal Logic:
- Fetching the API: The function retrieves the blockchain API instance using the
ConfigService
. - Converting URI to Identifier: The URI is converted into an identifier using
uriToIdentifier
. - Querying Blockchain Storage: It queries the
schemas
storage inschema
with the identifier. - Checking Existence: If the query returns
None
, the schema does not exist; otherwise, it exists.
Throws:
- Any error encountered while querying the blockchain API will be propagated as a rejected promise.
Dependencies:
- ConfigService: Retrieves the blockchain API instance.
- uriToIdentifier: Converts schema URI into a blockchain-compatible identifier.