Skip to content

Commit b4fe179

Browse files
authored
refactor: extract client instantiation to module (#36)
* refactor: extract client init into module Update identity register and retrieve to use * refactor: single client * style: fmt * chore: fix comment * refactor: change remaining identity and name scripts to use extracted client setup * refactor: change contract and document scripts to use extracted client setup * refactor: change name of client setup * refactor: change misc scripts to use new client * chore: run fmt * docs: update readme to mention client option info
1 parent f42be3a commit b4fe179

27 files changed

Lines changed: 132 additions & 270 deletions

1-Identities-and-Names/identity-register.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/register-an-identity.html
2-
const Dash = require('dash');
3-
const dotenv = require('dotenv');
4-
dotenv.config();
2+
const setupDashClient = require('../setupDashClient');
53

6-
const clientOpts = {
7-
network: process.env.NETWORK,
8-
wallet: {
9-
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
10-
unsafeOptions: {
11-
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // sync starting at this Core block height
12-
},
13-
},
14-
};
15-
const client = new Dash.Client(clientOpts);
4+
const client = setupDashClient();
165

176
const createIdentity = async () => {
187
return client.platform.identities.register();

1-Identities-and-Names/identity-retrieve-account-ids.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/retrieve-an-accounts-identities.html
2-
const Dash = require('dash');
3-
const dotenv = require('dotenv');
4-
dotenv.config();
2+
const setupDashClient = require('../setupDashClient');
53

6-
const client = new Dash.Client({
7-
network: process.env.NETWORK,
8-
wallet: {
9-
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
10-
unsafeOptions: {
11-
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // sync starting at this Core block height
12-
},
13-
},
14-
});
4+
const client = setupDashClient();
155

166
const retrieveIdentityIds = async () => {
177
const account = await client.getWalletAccount();

1-Identities-and-Names/identity-retrieve.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/retrieve-an-identity.html
2-
const Dash = require('dash');
3-
const dotenv = require('dotenv');
4-
dotenv.config();
2+
const setupDashClient = require('../setupDashClient');
53

6-
const client = new Dash.Client({ network: process.env.NETWORK });
4+
const client = setupDashClient();
75

86
const retrieveIdentity = async () => {
97
return client.platform.identities.get(process.env.IDENTITY_ID); // Your identity ID

1-Identities-and-Names/identity-topup.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/topup-an-identity-balance.html
2-
const Dash = require('dash');
3-
const dotenv = require('dotenv');
4-
dotenv.config();
2+
const setupDashClient = require('../setupDashClient');
53

6-
const clientOpts = {
7-
network: process.env.NETWORK,
8-
wallet: {
9-
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
10-
unsafeOptions: {
11-
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // sync starting at this Core block height
12-
},
13-
},
14-
};
15-
const client = new Dash.Client(clientOpts);
4+
const client = setupDashClient();
165

176
const topupIdentity = async () => {
187
const identityId = process.env.IDENTITY_ID; // Your identity ID

1-Identities-and-Names/identity-transfer-credits.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/transfer-credits-to-an-identity.html
2-
const Dash = require('dash');
3-
const dotenv = require('dotenv');
4-
dotenv.config();
2+
const setupDashClient = require('../setupDashClient');
53

6-
const clientOpts = {
7-
network: process.env.NETWORK,
8-
wallet: {
9-
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
10-
unsafeOptions: {
11-
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // only sync from mid-2023
12-
},
13-
},
14-
};
15-
const client = new Dash.Client(clientOpts);
4+
const client = setupDashClient();
165

176
const transferCredits = async () => {
187
const identityId = process.env.IDENTITY_ID; // Your identity ID

1-Identities-and-Names/identity-update-add-key.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,9 @@ const Dash = require('dash');
33
const {
44
PlatformProtocol: { IdentityPublicKey, IdentityPublicKeyWithWitness },
55
} = Dash;
6-
const dotenv = require('dotenv');
7-
dotenv.config();
8-
9-
const clientOpts = {
10-
network: process.env.NETWORK,
11-
wallet: {
12-
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
13-
unsafeOptions: {
14-
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // sync starting at this Core block height
15-
},
16-
},
17-
};
18-
const client = new Dash.Client(clientOpts);
6+
const setupDashClient = require('../setupDashClient');
7+
8+
const client = setupDashClient();
199

2010
const updateIdentityAddKey = async () => {
2111
const identityId = process.env.IDENTITY_ID;

1-Identities-and-Names/identity-update-disable-key.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/update-an-identity.html
2-
const Dash = require('dash');
3-
const dotenv = require('dotenv');
4-
dotenv.config();
2+
const setupDashClient = require('../setupDashClient');
53

6-
const clientOpts = {
7-
network: process.env.NETWORK,
8-
wallet: {
9-
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
10-
unsafeOptions: {
11-
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // sync starting at this Core block height
12-
},
13-
},
14-
};
15-
const client = new Dash.Client(clientOpts);
4+
const client = setupDashClient();
165

176
const updateIdentityDisableKey = async () => {
187
const identityId = process.env.IDENTITY_ID;
19-
const keyId = 2; // One of the identity's public key IDs
8+
const keyId = 3; // One of the identity's public key IDs
209

2110
// Retrieve the identity to be updated and the public key to disable
2211
const existingIdentity = await client.platform.identities.get(identityId);

1-Identities-and-Names/name-register-alias.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/register-a-name-for-an-identity.html
2-
const Dash = require('dash');
3-
const dotenv = require('dotenv');
4-
dotenv.config();
2+
const setupDashClient = require('../setupDashClient');
53

6-
const aliasToRegister = ''; // Enter alias to register
7-
8-
const clientOpts = {
9-
network: process.env.NETWORK,
10-
wallet: {
11-
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
12-
unsafeOptions: {
13-
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // sync starting at this Core block height
14-
},
15-
},
16-
};
17-
const client = new Dash.Client(clientOpts);
4+
const client = setupDashClient();
185

196
const registerAlias = async () => {
207
const platform = client.platform;

1-Identities-and-Names/name-register.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/register-a-name-for-an-identity.html
2-
const Dash = require('dash');
3-
const dotenv = require('dotenv');
4-
dotenv.config();
2+
const setupDashClient = require('../setupDashClient');
53

6-
const nameToRegister = ''; // Enter name to register
7-
8-
const clientOpts = {
9-
network: process.env.NETWORK,
10-
wallet: {
11-
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
12-
unsafeOptions: {
13-
skipSynchronizationBeforeHeight: process.env.SYNC_START_HEIGHT, // sync starting at this Core block height
14-
},
15-
},
16-
};
17-
const client = new Dash.Client(clientOpts);
4+
const client = setupDashClient();
185

196
const registerName = async () => {
207
const { platform } = client;

1-Identities-and-Names/name-resolve-by-name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/identities-and-names/retrieve-a-name.html
2-
const Dash = require('dash');
2+
const setupDashClient = require('../setupDashClient');
33

4-
const client = new Dash.Client({ network: process.env.NETWORK });
4+
const client = setupDashClient();
55

66
const nameToRetrieve = ''; // Enter name to retrieve
77

0 commit comments

Comments
 (0)