-
Notifications
You must be signed in to change notification settings - Fork 5
/
contract-register-nft.js
86 lines (80 loc) · 2.44 KB
/
contract-register-nft.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/contracts-and-documents/register-a-data-contract.html
const setupDashClient = require('../setupDashClient');
const client = setupDashClient();
const registerContract = async () => {
const { platform } = client;
const identity = await platform.identities.get(process.env.IDENTITY_ID); // Your identity ID
const contractDocuments = {
card: {
type: 'object',
documentsMutable: false, // true = documents can be modified (replaced)
canBeDeleted: true, // true = documents can be deleted (current bug prevents deletion when true if mutable is false)
transferable: 1, // 0 = transfers disabled; 1 = transfers enabled
tradeMode: 1, // 0 = no trading; 1 = direct purchases
creationRestrictionMode: 1, // 0 = anyone can mint; 1 = only contract owner can mint
properties: {
name: {
type: 'string',
description: 'Name of the card',
minLength: 0,
maxLength: 63,
position: 0,
},
description: {
type: 'string',
description: 'Description of the card',
minLength: 0,
maxLength: 256,
position: 1,
},
attack: {
type: 'integer',
description: 'Attack power of the card',
position: 2,
},
defense: {
type: 'integer',
description: 'Defense level of the card',
position: 3,
},
},
indices: [
{
name: 'owner',
properties: [
{
$ownerId: 'asc',
},
],
},
{
name: 'attack',
properties: [
{
attack: 'asc',
},
],
},
{
name: 'defense',
properties: [
{
defense: 'asc',
},
],
},
],
required: ['name', 'attack', 'defense'],
additionalProperties: false,
},
};
const contract = await platform.contracts.create(contractDocuments, identity);
console.dir({ contract: contract.toJSON() });
// Sign and submit the data contract
await platform.contracts.publish(contract, identity);
return contract;
};
registerContract()
.then((d) => console.log('Contract registered:\n', d.toJSON()))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());