Skip to content

Commit fe2a5c3

Browse files
authored
feat: v1.4.0 update and withdrawal tutorial (#44)
* chore: update to platform v1.4-dev.8 * feat: credit withdrawal tutorial * style: run npm fmt * chore: update to platform v1.4 * chore: small updates * style: npm run fmt update * chore: fix link
1 parent f8623d2 commit fe2a5c3

File tree

4 files changed

+740
-278
lines changed

4 files changed

+740
-278
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/withdraw-an-identity-balance.html
2+
const setupDashClient = require('../setupDashClient');
3+
4+
const client = setupDashClient();
5+
6+
const withdrawCredits = async () => {
7+
const identityId = process.env.IDENTITY_ID; // Your identity ID
8+
const identity = await client.platform.identities.get(identityId);
9+
10+
console.log('Identity balance before transfer: ', identity.balance);
11+
12+
const toAddress = process.env.WITHDRAWAL_ADDRESS; // Destination Dash address
13+
const amount = 1000000; // Number of credits to withdraw
14+
const amountDash = amount / (1000 * 100000000);
15+
16+
console.log(`Withdrawing ${amount} credits (${amountDash} DASH)`);
17+
18+
// Temporarily force minRelay to have a value so withdrawal succeeds
19+
// https://github.com/dashpay/platform/issues/2233
20+
client.wallet.storage.getDefaultChainStore().state.fees.minRelay = 1000;
21+
// console.log(client.wallet.storage.getDefaultChainStore().state.fees.minRelay)
22+
23+
const response = await client.platform.identities.withdrawCredits(
24+
identity,
25+
amount,
26+
{
27+
toAddress,
28+
},
29+
);
30+
console.log(response);
31+
return client.platform.identities.get(identityId);
32+
};
33+
34+
withdrawCredits()
35+
.then((d) => console.log('Identity balance after withdrawal: ', d.balance))
36+
.catch((e) => console.error('Something went wrong:\n', e))
37+
.finally(() => client.disconnect());

2-Contracts-and-Documents/contract-register-nft.js

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,68 @@ const registerContract = async () => {
99

1010
const contractDocuments = {
1111
card: {
12-
type: "object",
12+
type: 'object',
1313
documentsMutable: false, // true = documents can be modified (replaced)
1414
canBeDeleted: true, // true = documents can be deleted (current bug prevents deletion when true if mutable is false)
1515
transferable: 1, // 0 = transfers disabled; 1 = transfers enabled
1616
tradeMode: 1, // 0 = no trading; 1 = direct purchases
1717
creationRestrictionMode: 1, // 0 = anyone can mint; 1 = only contract owner can mint
1818
properties: {
1919
name: {
20-
type: "string",
21-
description: "Name of the card",
20+
type: 'string',
21+
description: 'Name of the card',
2222
minLength: 0,
2323
maxLength: 63,
24-
position: 0
24+
position: 0,
2525
},
2626
description: {
27-
type: "string",
28-
description: "Description of the card",
27+
type: 'string',
28+
description: 'Description of the card',
2929
minLength: 0,
3030
maxLength: 256,
31-
position: 1
31+
position: 1,
3232
},
3333
attack: {
34-
type: "integer",
35-
description: "Attack power of the card",
36-
position: 2
34+
type: 'integer',
35+
description: 'Attack power of the card',
36+
position: 2,
3737
},
3838
defense: {
39-
type: "integer",
40-
description: "Defense level of the card",
41-
position: 3
42-
}
39+
type: 'integer',
40+
description: 'Defense level of the card',
41+
position: 3,
42+
},
4343
},
4444
indices: [
4545
{
46-
name: "owner",
46+
name: 'owner',
4747
properties: [
4848
{
49-
$ownerId: "asc"
50-
}
51-
]
49+
$ownerId: 'asc',
50+
},
51+
],
5252
},
5353
{
54-
name: "attack",
54+
name: 'attack',
5555
properties: [
5656
{
57-
attack: "asc"
58-
}
59-
]
57+
attack: 'asc',
58+
},
59+
],
6060
},
6161
{
62-
name: "defense",
62+
name: 'defense',
6363
properties: [
6464
{
65-
defense: "asc"
66-
}
67-
]
68-
}
69-
],
70-
required: [
71-
"name",
72-
"attack",
73-
"defense"
65+
defense: 'asc',
66+
},
67+
],
68+
},
7469
],
75-
additionalProperties: false
76-
}
77-
}
70+
required: ['name', 'attack', 'defense'],
71+
additionalProperties: false,
72+
},
73+
};
7874

7975
const contract = await platform.contracts.create(contractDocuments, identity);
8076
console.dir({ contract: contract.toJSON() });

0 commit comments

Comments
 (0)