dispatchToChain
dispatchToChain(
schema
,creator
,authorAccount
,authorization
,signCallback
):Promise
<SchemaId
>
Dispatches a schema to the blockchain for storage and tracking. This function handles the submission of a schema object to the blockchain, ensuring its uniqueness, immutability, and verifiability in a decentralized environment. It involves encoding the schema, signing the transaction using the author’s blockchain account, and employing the creator’s DID for identity verification. The function also requires an authorization ID for transaction permissioning and a callback function for signing the transaction (extrinsic).
Parameters
• schema: ISchema
The schema object, typically representing a structured data format defining data requirements.
• creator: did:cord:3${string}
The decentralized identifier (DID) URI representing the digital identity of the creator.
• authorAccount: CordKeyringPair
The blockchain account of the author, used for.
• authorization: string
A unique identifier for authorization purposes, authenticating and signing the transaction. often associated with specific permissions.
• signCallback: SignExtrinsicCallback
A callback function that handles the signing of the blockchain transaction (extrinsic).
Returns
Promise
<SchemaId
>
A promise that resolves to the unique ID of the dispatched schema upon successful processing by the blockchain.
The function employs a try-catch block to handle potential errors during the dispatch process, such as issues with transaction creation or network failures. In case of an error, it throws an informative exception.
Example
async function exampleSchemaDispatch() { // Initialize schema data and necessary parameters const schema = { schema data }; const authorAccount = { author's blockchain account }; const creator = 'did:cord:example'; const authorization = 'authorization-id'; const signCallback = (tx: any) => { /* signing logic };
try { const schemaId = await dispatchToChain(schema, authorAccount, creator, authorization, signCallback); console.log('Schema dispatched with ID:', schemaId); } catch (error) { console.error('Error dispatching schema:', error); }}
// Example usageexampleSchemaDispatch();