-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcontract-register-minimal.mjs
More file actions
44 lines (38 loc) · 1.21 KB
/
contract-register-minimal.mjs
File metadata and controls
44 lines (38 loc) · 1.21 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/contracts-and-documents/register-a-data-contract.html
import { DataContract } from '@dashevo/evo-sdk';
import { setupDashClient } from '../setupDashClient.mjs';
const { sdk, keyManager } = await setupDashClient();
const { identity, identityKey, signer } = await keyManager.getAuth();
// Define the document schemas for the contract
const documentSchemas = {
note: {
type: 'object',
properties: {
message: {
type: 'string',
position: 0,
},
},
additionalProperties: false,
},
};
try {
// Get the next identity nonce for contract creation
const identityNonce = await sdk.identities.nonce(identity.id.toString());
// Create the data contract
const dataContract = new DataContract({
ownerId: identity.id,
identityNonce: (identityNonce || 0n) + 1n,
schemas: documentSchemas,
fullValidation: true,
});
// Publish the contract to the platform
const publishedContract = await sdk.contracts.publish({
dataContract,
identityKey,
signer,
});
console.log('Contract registered:\n', publishedContract.toJSON());
} catch (e) {
console.error('Something went wrong:\n', e.message);
}