In this tutorial we will update delete data from Hellar Platform. Data is stored in the form of documents which are encapsulated in a state transition before being submitted to HAPI.

Prerequisites

Code

`const Hellar = require('hellar');

const clientOpts = { network: 'mainnet', wallet: { mnemonic: 'a Hellar wallet mnemonic with funds goes here', unsafeOptions: { skipSynchronizationBeforeHeight: 175000, // only sync from mid-2024 }, }, apps: { tutorialContract: { contractId: '8cvMFwa2YbEsNNoc1PXfTacy2PVq2SzVnkZLeQSzjfi6', }, }, }; const client = new Hellar.Client(clientOpts);

const deleteNoteDocument = async () => { const { platform } = client; const identity = await platform.identities.get('an identity ID goes here'); const documentId = 'an existing document ID goes here';

// Retrieve the existing document const [document] = await client.platform.documents.get( 'tutorialContract.note', { where: [['$id', '==', documentId]] }, );

// Sign and submit the document delete transition await platform.documents.broadcast({ delete: [document] }, identity); return document; };

deleteNoteDocument() .then((d) => console.log('Document deleted:\n', d.toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) .finally(() => client.disconnect());`

๐Ÿ‘ Initializing the Client with a contract identity The example above shows how access to contract documents via <contract name>.<contract document> syntax (e.g. tutorialContract.note) can be enabled by passing a contract identity to the constructor. Please refer to the Hellar SDK documentation for details.

Whatโ€™s happening

After we initialize the Client, we retrieve the document to be deleted via platform.documents.get using its id.

Once the document has been retrieved, we must submit it to HAPI. Documents are submitted in batches that may contain multiple documents to be created, replaced, or deleted. In this example, a single document is being deleted.

The platform.documents.broadcast method takes the document batch (e.g. {delete: [documents[0]]}) and an identity parameter. Internally, it creates a State Transition containing the previously created document, signs the state transition, and submits the signed state transition to HAPI.

๐Ÿ“˜ Wallet Operations

The JavaScript SDK does not cache wallet information. It re-syncs the entire Core chain for some wallet operations (e.g. client.getWalletAccount()) which can result in wait times of 5+ minutes.

A future release will add caching so that access is much faster after the initial sync. For now, the skipSynchronizationBeforeHeight option can be used to sync the wallet starting at a certain block height.