diff --git a/1-Identities-and-Names/identity-register.js b/1-Identities-and-Names/identity-register.js index 8a6ff53..3554ab7 100644 --- a/1-Identities-and-Names/identity-register.js +++ b/1-Identities-and-Names/identity-register.js @@ -21,4 +21,4 @@ const createIdentity = async () => { createIdentity() .then((d) => console.log('Identity:\n', d.toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/1-Identities-and-Names/identity-retrieve-account-ids.js b/1-Identities-and-Names/identity-retrieve-account-ids.js index 2addfcb..86e636f 100644 --- a/1-Identities-and-Names/identity-retrieve-account-ids.js +++ b/1-Identities-and-Names/identity-retrieve-account-ids.js @@ -21,4 +21,4 @@ const retrieveIdentityIds = async () => { retrieveIdentityIds() .then((d) => console.log('Mnemonic identities:\n', d)) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/1-Identities-and-Names/identity-topup.js b/1-Identities-and-Names/identity-topup.js index fc51ded..3f39570 100644 --- a/1-Identities-and-Names/identity-topup.js +++ b/1-Identities-and-Names/identity-topup.js @@ -25,4 +25,4 @@ const topupIdentity = async () => { topupIdentity() .then((d) => console.log('Identity credit balance: ', d.balance)) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/1-Identities-and-Names/name-register-alias.js b/1-Identities-and-Names/name-register-alias.js index 05c5613..66a0a02 100644 --- a/1-Identities-and-Names/name-register-alias.js +++ b/1-Identities-and-Names/name-register-alias.js @@ -7,7 +7,7 @@ const aliasToRegister = ''; // Enter alias to register const clientOpts = { wallet: { - mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds + mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds unsafeOptions: { skipSynchronizationBeforeHeight: 675000, // only sync from early-2022 }, @@ -30,4 +30,4 @@ const registerAlias = async () => { registerAlias() .then((d) => console.log('Alias registered:\n', d.toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/1-Identities-and-Names/name-register.js b/1-Identities-and-Names/name-register.js index ea1215d..5cab61e 100644 --- a/1-Identities-and-Names/name-register.js +++ b/1-Identities-and-Names/name-register.js @@ -7,7 +7,7 @@ const nameToRegister = ''; // Enter name to register const clientOpts = { wallet: { - mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds + mnemonic: process.env.MNEMONIC, // A Dash wallet mnemonic with testnet funds unsafeOptions: { skipSynchronizationBeforeHeight: 675000, // only sync from early-2022 }, @@ -31,4 +31,4 @@ const registerName = async () => { registerName() .then((d) => console.log('Name registered:\n', d.toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/1-Identities-and-Names/name-resolve-by-name.js b/1-Identities-and-Names/name-resolve-by-name.js index e17efb1..2647d1d 100644 --- a/1-Identities-and-Names/name-resolve-by-name.js +++ b/1-Identities-and-Names/name-resolve-by-name.js @@ -13,4 +13,4 @@ const retrieveName = async () => { retrieveName() .then((d) => console.log('Name retrieved:\n', d.toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/1-Identities-and-Names/name-resolve-by-record.js b/1-Identities-and-Names/name-resolve-by-record.js index 9d53cb5..a47b41d 100644 --- a/1-Identities-and-Names/name-resolve-by-record.js +++ b/1-Identities-and-Names/name-resolve-by-record.js @@ -16,4 +16,4 @@ const retrieveNameByRecord = async () => { retrieveNameByRecord() .then((d) => console.log('Name retrieved:\n', d[0].toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/1-Identities-and-Names/name-search-by-name.js b/1-Identities-and-Names/name-search-by-name.js index 943dc37..96e117e 100644 --- a/1-Identities-and-Names/name-search-by-name.js +++ b/1-Identities-and-Names/name-search-by-name.js @@ -19,4 +19,4 @@ retrieveNameBySearch() } }) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/2-Contracts-and-Documents/contract-register-minimal.js b/2-Contracts-and-Documents/contract-register-minimal.js index 57a075a..43d1dd1 100644 --- a/2-Contracts-and-Documents/contract-register-minimal.js +++ b/2-Contracts-and-Documents/contract-register-minimal.js @@ -48,4 +48,4 @@ const registerContract = async () => { registerContract() .then((d) => console.log('Contract registered:\n', d.toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/2-Contracts-and-Documents/contract-retrieve.js b/2-Contracts-and-Documents/contract-retrieve.js index 33bc0cc..d281370 100644 --- a/2-Contracts-and-Documents/contract-retrieve.js +++ b/2-Contracts-and-Documents/contract-retrieve.js @@ -13,4 +13,4 @@ const retrieveContract = async () => { retrieveContract() .then((d) => console.dir(d.toJSON(), { depth: 5 })) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/2-Contracts-and-Documents/contract-update-minimal.js b/2-Contracts-and-Documents/contract-update-minimal.js index 4a8d68c..7c1f1ca 100644 --- a/2-Contracts-and-Documents/contract-update-minimal.js +++ b/2-Contracts-and-Documents/contract-update-minimal.js @@ -17,7 +17,9 @@ const updateContract = async () => { const { platform } = client; const identity = await platform.identities.get(process.env.IDENTITY_ID); // Your identity ID - const existingDataContract = await platform.contracts.get(process.env.CONTRACT_ID); + const existingDataContract = await platform.contracts.get( + process.env.CONTRACT_ID, + ); const documents = existingDataContract.getDocuments(); documents.note.properties.author = { @@ -25,10 +27,12 @@ const updateContract = async () => { }; existingDataContract.setDocuments(documents); - + // Make sure contract passes validation checks await platform.dpp.initialize(); - const validationResult = await platform.dpp.dataContract.validate(existingDataContract); + const validationResult = await platform.dpp.dataContract.validate( + existingDataContract, + ); if (validationResult.isValid()) { console.log('Validation passed, broadcasting contract..'); @@ -42,4 +46,4 @@ const updateContract = async () => { updateContract() .then((d) => console.log('Contract updated:\n', d.toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/2-Contracts-and-Documents/document-delete.js b/2-Contracts-and-Documents/document-delete.js index 7c927e5..8ca7dda 100644 --- a/2-Contracts-and-Documents/document-delete.js +++ b/2-Contracts-and-Documents/document-delete.js @@ -36,4 +36,4 @@ const deleteNoteDocument = async () => { deleteNoteDocument() .then((d) => console.log('Document deleted:\n', d)) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/2-Contracts-and-Documents/document-retrieve.js b/2-Contracts-and-Documents/document-retrieve.js index 9b8bab6..d1e8472 100644 --- a/2-Contracts-and-Documents/document-retrieve.js +++ b/2-Contracts-and-Documents/document-retrieve.js @@ -13,12 +13,9 @@ const clientOpts = { const client = new Dash.Client(clientOpts); const getDocuments = async () => { - return client.platform.documents.get( - 'tutorialContract.note', - { - limit: 2, // Only retrieve 2 document - }, - ); + return client.platform.documents.get('tutorialContract.note', { + limit: 2, // Only retrieve 2 document + }); }; getDocuments() @@ -28,4 +25,4 @@ getDocuments() } }) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/2-Contracts-and-Documents/document-submit.js b/2-Contracts-and-Documents/document-submit.js index 895d095..6c2deb7 100644 --- a/2-Contracts-and-Documents/document-submit.js +++ b/2-Contracts-and-Documents/document-submit.js @@ -36,8 +36,8 @@ const submitNoteDocument = async () => { const documentBatch = { create: [noteDocument], // Document(s) to create - replace: [], // Document(s) to update - delete: [], // Document(s) to delete + replace: [], // Document(s) to update + delete: [], // Document(s) to delete }; // Sign and submit the document(s) return platform.documents.broadcast(documentBatch, identity); @@ -46,4 +46,4 @@ const submitNoteDocument = async () => { submitNoteDocument() .then((d) => console.log(d.toJSON())) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/2-Contracts-and-Documents/document-update.js b/2-Contracts-and-Documents/document-update.js index 3704cf2..dc11819 100644 --- a/2-Contracts-and-Documents/document-update.js +++ b/2-Contracts-and-Documents/document-update.js @@ -39,4 +39,4 @@ const updateNoteDocument = async () => { updateNoteDocument() .then((d) => console.log('Document updated:\n', d)) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/README.md b/README.md index d7926fe..3420913 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,17 @@ [![SDK Version](https://img.shields.io/github/package-json/dependency-version/dashevo/platform-readme-tutorials/dash)](https://github.com/dashevo/platform-readme-tutorials/blob/main/package.json) -Code for the tutorials found on the [Platform documentation site](https://dashplatform.readme.io/). +Code for the tutorials found on the +[Platform documentation site](https://dashplatform.readme.io/). ## Install -Note: [NodeJS](https://nodejs.org/en/download/) (v12+) must be installed to run the tutorial code. +Note: [NodeJS](https://nodejs.org/en/download/) (v12+) must be installed to run +the tutorial code. ### Clone this repository -``` shell +```shell git clone https://github.com/dashevo/platform-readme-tutorials.git ``` @@ -18,7 +20,7 @@ git clone https://github.com/dashevo/platform-readme-tutorials.git Do a clean install of project dependencies: -``` shell +```shell npm ci ``` @@ -26,15 +28,16 @@ npm ci 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. - -Proceed with the tutorials [Identities and Names tutorials](./1-Identities-and-Names/) first and the -[Contracts And Documents tutorials](./2-Contracts-and-Documents/) next. They align with the -tutorials section found on the [documentation -site](https://dashplatform.readme.io/docs/tutorials-introduction). +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. + +Proceed with the tutorials +[Identities and Names tutorials](./1-Identities-and-Names/) first and the +[Contracts And Documents tutorials](./2-Contracts-and-Documents/) next. They +align with the tutorials section found on the +[documentation site](https://dashplatform.readme.io/docs/tutorials-introduction). ## Contributing diff --git a/connect.js b/connect.js index 4c13285..ba2ee8b 100644 --- a/connect.js +++ b/connect.js @@ -10,4 +10,4 @@ async function connect() { connect() .then((d) => console.log('Connected. Best block hash:\n', d)) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect()); diff --git a/create-wallet.js b/create-wallet.js index 248674b..e6903e6 100644 --- a/create-wallet.js +++ b/create-wallet.js @@ -5,10 +5,10 @@ const clientOpts = { network: 'testnet', 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 - // replace 'null' with an existing wallet mnemonic - offlineMode: true, // this indicates we don't want to sync the chain - // it can only be used when the mnemonic is set to 'null' + // if you want to get a new address for an existing wallet + // replace 'null' with an existing wallet mnemonic + offlineMode: true, // this indicates we don't want to sync the chain + // it can only be used when the mnemonic is set to 'null' }, }; @@ -31,4 +31,4 @@ createWallet() client.on('error', (error, context) => { console.error(`Client error: ${error.name}`); console.error(context); -}); \ No newline at end of file +}); diff --git a/send-funds.js b/send-funds.js index f224ef8..3297634 100644 --- a/send-funds.js +++ b/send-funds.js @@ -33,4 +33,4 @@ sendFunds() client.on('error', (error, context) => { console.error(`Client error: ${error.name}`); console.error(context); -}); \ No newline at end of file +}); diff --git a/use-dapi-client-methods.js b/use-dapi-client-methods.js index f6a70ee..4711940 100644 --- a/use-dapi-client-methods.js +++ b/use-dapi-client-methods.js @@ -14,4 +14,4 @@ async function dapiClientMethods() { dapiClientMethods() .then((d) => console.log('Core status:\n', d)) .catch((e) => console.error('Something went wrong:\n', e)) - .finally(() => client.disconnect()); \ No newline at end of file + .finally(() => client.disconnect());