-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdocument-update.js
28 lines (22 loc) · 1.03 KB
/
document-update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/contracts-and-documents/update-documents.html
const setupDashClient = require('../setupDashClient');
const client = setupDashClient();
const updateNoteDocument = async () => {
const { platform } = client;
const identity = await platform.identities.get(process.env.IDENTITY_ID); // Your identity ID
const documentId = process.env.DOCUMENT_ID; // An existing document
// Retrieve the existing document
const [document] = await client.platform.documents.get(
'tutorialContract.note',
{ where: [['$id', '==', documentId]] },
);
// Update document
document.set('message', `Updated document @ ${new Date().toUTCString()}`);
// Sign and submit the document replace transition
await platform.documents.broadcast({ replace: [document] }, identity);
return document;
};
updateNoteDocument()
.then((d) => console.log('Document updated:\n', d.toJSON()))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());