Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ MNEMONIC='jewel pattern cry forget gown better agent celery nothing glove silk i
# IDENTITY_ID comes from the "$id" found in the "identity-register.js" response
IDENTITY_ID='6cSbshXPYDA2CmBtD31X4uo7YLwtef4mVDt15zRok8Xg'
# CONTRACT_ID comes from the "$id" found in the "contract-register-minimal.js" response
CONTRACT_ID='4BRJbxsDTFY4GJGrCqM6KUjv1wSQDBuUYiGkuzgcrD5d'
CONTRACT_ID='4BRJbxsDTFY4GJGrCqM6KUjv1wSQDBuUYiGkuzgcrD5d'
# NETWORK sets which network to connect to: testnet, devnet, or local
NETWORK='testnet'
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/identity-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: 'testnet',
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/identity-retrieve-account-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const client = new Dash.Client({
network: 'testnet',
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/identity-retrieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();

const client = new Dash.Client();
const client = new Dash.Client({ network: process.env.NETWORK });

const retrieveIdentity = async () => {
return client.platform.identities.get(process.env.IDENTITY_ID); // Your identity ID
Expand Down
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/identity-topup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: 'testnet',
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
57 changes: 57 additions & 0 deletions 1-Identities-and-Names/identity-update-add-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// See https://dashplatform.readme.io/docs/tutorial-update-an-identity
const Dash = require('dash');
const IdentityPublicKey = require('@dashevo/dpp/lib/identity/IdentityPublicKey');
const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
skipSynchronizationBeforeHeight: 675000, // only sync from early-2022
},
},
};
const client = new Dash.Client(clientOpts);

const updateIdentityAddKey = async () => {
const identityId = process.env.IDENTITY_ID;
const existingIdentity = await client.platform.identities.get(identityId);
const newKeyId = existingIdentity.toJSON().publicKeys.length;

// Get an unused identity index
const account = await client.platform.client.getWalletAccount();
const identityIndex = await account.getUnusedIdentityIndex();

// Get unused private key and construct new identity public key
const { privateKey: identityPrivateKey } =
account.identities.getIdentityHDKeyByIndex(identityIndex, 0);

const identityPublicKey = identityPrivateKey.toPublicKey().toBuffer();

const newPublicKey = new IdentityPublicKey({
id: newKeyId,
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
securityLevel: IdentityPublicKey.SECURITY_LEVELS.HIGH,
data: identityPublicKey,
readOnly: false,
});

const updateAdd = {
add: [newPublicKey],
};

// Submit the update signed with the new key
await client.platform.identities.update(existingIdentity, updateAdd, {
[newPublicKey.getId()]: identityPrivateKey,
});

return client.platform.identities.get(identityId);
};

updateIdentityAddKey()
.then((d) => console.log('Identity updated:\n', d.toJSON()))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
38 changes: 38 additions & 0 deletions 1-Identities-and-Names/identity-update-disable-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// See https://dashplatform.readme.io/docs/tutorial-update-an-identity
const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
skipSynchronizationBeforeHeight: 675000, // only sync from early-2022
},
},
};
const client = new Dash.Client(clientOpts);

const updateIdentityDisableKey = async () => {
const identityId = process.env.IDENTITY_ID;
const keyId = 2; // One of the identity's public key IDs

// Retrieve the identity to be updated and the public key to disable
const existingIdentity = await client.platform.identities.get(identityId);
// console.log(existingIdentity.toJSON())
const publicKeyToDisable = existingIdentity.getPublicKeyById(keyId);
// console.log(publicKeyToDisable)

const updateDisable = {
disable: [publicKeyToDisable],
};

await client.platform.identities.update(existingIdentity, updateDisable);
return client.platform.identities.get(identityId);
};

updateIdentityDisableKey()
.then((d) => console.log('Identity updated:\n', d.toJSON()))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
1 change: 1 addition & 0 deletions 1-Identities-and-Names/name-register-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dotenv.config();
const aliasToRegister = ''; // Enter alias to register

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
1 change: 1 addition & 0 deletions 1-Identities-and-Names/name-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dotenv.config();
const nameToRegister = ''; // Enter name to register

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/name-resolve-by-name.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// See https://dashplatform.readme.io/docs/tutorial-retrieve-a-name
const Dash = require('dash');

const client = new Dash.Client();
const client = new Dash.Client({ network: process.env.NETWORK });

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

Expand Down
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/name-resolve-by-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();

const client = new Dash.Client();
const client = new Dash.Client({ network: process.env.NETWORK });

const retrieveNameByRecord = async () => {
// Retrieve by a name's identity ID
Expand Down
2 changes: 1 addition & 1 deletion 1-Identities-and-Names/name-search-by-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dotenv.config();

const searchPrefix = 'a'; // Enter prefix character(s) to search for

const client = new Dash.Client();
const client = new Dash.Client({ network: process.env.NETWORK });

const retrieveNameBySearch = async () => {
// Search for names (e.g. `user*`)
Expand Down
1 change: 1 addition & 0 deletions 2-Contracts-and-Documents/contract-register-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
2 changes: 1 addition & 1 deletion 2-Contracts-and-Documents/contract-retrieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();

const client = new Dash.Client();
const client = new Dash.Client({ network: process.env.NETWORK });

const retrieveContract = async () => {
const contractId = process.env.CONTRACT_ID; // Your contract ID
Expand Down
1 change: 1 addition & 0 deletions 2-Contracts-and-Documents/contract-update-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
1 change: 1 addition & 0 deletions 2-Contracts-and-Documents/document-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
1 change: 1 addition & 0 deletions 2-Contracts-and-Documents/document-retrieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: process.env.NETWORK,
apps: {
tutorialContract: {
contractId: process.env.CONTRACT_ID, // Your contract ID
Expand Down
2 changes: 1 addition & 1 deletion 2-Contracts-and-Documents/document-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: 'testnet',
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
1 change: 1 addition & 0 deletions 2-Contracts-and-Documents/document-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: process.env.NETWORK,
wallet: {
mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds
unsafeOptions: {
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ npm ci

## Usage

1. Create an `.env` file (See [`.env.example`](./.env.example) for an example
`.env` file). Set `NETWORK` to the desired network type (normally 'testnet').
1. Check connection: `node connect.js`
1. Create wallet: `node create-wallet.js`
1. Go to the [Testnet faucet](https://testnet-faucet.dash.org/) and add funds to
the address reported in the previous step
1. Create an `.env` file (See [`.env.example`](./.env.example) for an example
`.env` file). Set `MNEMONIC` to the wallet mnemonic from step 2.
1. Open the `.env` file (See [`.env.example`](./.env.example) for an example
`.env` file) and set `MNEMONIC` to the wallet mnemonic from step 3.

Proceed with the tutorials
[Identities and Names tutorials](./1-Identities-and-Names/) first and the
Expand Down
4 changes: 3 additions & 1 deletion connect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// See https://dashplatform.readme.io/docs/tutorial-connecting-to-testnet
const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();

const client = new Dash.Client();
const client = new Dash.Client({ network: process.env.NETWORK });

async function connect() {
return await client.getDAPIClient().core.getBestBlockHash();
Expand Down
4 changes: 3 additions & 1 deletion create-wallet.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// See https://dashplatform.readme.io/docs/tutorial-create-and-fund-a-wallet
const Dash = require('dash');
const dotenv = require('dotenv');
dotenv.config();

const clientOpts = {
network: 'testnet',
network: process.env.NETWORK,
wallet: {
mnemonic: null, // this indicates that we want a new wallet to be generated
// if you want to get a new address for an existing wallet
Expand Down
Loading