Skip to content

Commit eb5a453

Browse files
authored
feat: add example nft contract (#38)
Shows options that can be used for NFT features
1 parent 848b913 commit eb5a453

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/contracts-and-documents/register-a-data-contract.html
2+
const setupDashClient = require('../setupDashClient');
3+
4+
const client = setupDashClient();
5+
6+
const registerContract = async () => {
7+
const { platform } = client;
8+
const identity = await platform.identities.get(process.env.IDENTITY_ID); // Your identity ID
9+
10+
const contractDocuments = {
11+
card: {
12+
type: "object",
13+
documentsMutable: false, // true = documents can be modified (replaced)
14+
canBeDeleted: true, // true = documents can be deleted (current bug prevents deletion when true if mutable is false)
15+
transferable: 1, // 0 = transfers disabled; 1 = transfers enabled
16+
tradeMode: 1, // 0 = no trading; 1 = direct purchases
17+
creationRestrictionMode: 1, // 0 = anyone can mint; 1 = only contract owner can mint
18+
properties: {
19+
name: {
20+
type: "string",
21+
description: "Name of the card",
22+
minLength: 0,
23+
maxLength: 63,
24+
position: 0
25+
},
26+
description: {
27+
type: "string",
28+
description: "Description of the card",
29+
minLength: 0,
30+
maxLength: 256,
31+
position: 1
32+
},
33+
attack: {
34+
type: "integer",
35+
description: "Attack power of the card",
36+
position: 2
37+
},
38+
defense: {
39+
type: "integer",
40+
description: "Defense level of the card",
41+
position: 3
42+
}
43+
},
44+
indices: [
45+
{
46+
name: "owner",
47+
properties: [
48+
{
49+
$ownerId: "asc"
50+
}
51+
]
52+
},
53+
{
54+
name: "attack",
55+
properties: [
56+
{
57+
attack: "asc"
58+
}
59+
]
60+
},
61+
{
62+
name: "defense",
63+
properties: [
64+
{
65+
defense: "asc"
66+
}
67+
]
68+
}
69+
],
70+
required: [
71+
"name",
72+
"attack",
73+
"defense"
74+
],
75+
additionalProperties: false
76+
}
77+
}
78+
79+
const contract = await platform.contracts.create(contractDocuments, identity);
80+
console.dir({ contract: contract.toJSON() });
81+
82+
// Sign and submit the data contract
83+
await platform.contracts.publish(contract, identity);
84+
return contract;
85+
};
86+
87+
registerContract()
88+
.then((d) => console.log('Contract registered:\n', d.toJSON()))
89+
.catch((e) => console.error('Something went wrong:\n', e))
90+
.finally(() => client.disconnect());

0 commit comments

Comments
 (0)