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
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 @@ -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());
.finally(() => client.disconnect());
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 @@ -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());
.finally(() => client.disconnect());
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 @@ -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());
.finally(() => client.disconnect());
4 changes: 2 additions & 2 deletions 1-Identities-and-Names/name-register-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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());
.finally(() => client.disconnect());
4 changes: 2 additions & 2 deletions 1-Identities-and-Names/name-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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());
.finally(() => client.disconnect());
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
Expand Up @@ -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());
.finally(() => client.disconnect());
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 @@ -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());
.finally(() => client.disconnect());
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 @@ -19,4 +19,4 @@ retrieveNameBySearch()
}
})
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
.finally(() => client.disconnect());
2 changes: 1 addition & 1 deletion 2-Contracts-and-Documents/contract-register-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
.finally(() => client.disconnect());
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 @@ -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());
.finally(() => client.disconnect());
12 changes: 8 additions & 4 deletions 2-Contracts-and-Documents/contract-update-minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ 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 = {
type: 'string',
};

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..');
Expand All @@ -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());
.finally(() => client.disconnect());
2 changes: 1 addition & 1 deletion 2-Contracts-and-Documents/document-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
.finally(() => client.disconnect());
11 changes: 4 additions & 7 deletions 2-Contracts-and-Documents/document-retrieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -28,4 +25,4 @@ getDocuments()
}
})
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
.finally(() => client.disconnect());
6 changes: 3 additions & 3 deletions 2-Contracts-and-Documents/document-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
.finally(() => client.disconnect());
2 changes: 1 addition & 1 deletion 2-Contracts-and-Documents/document-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
.finally(() => client.disconnect());
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,42 @@

[![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
```

### Install project dependencies

Do a clean install of project dependencies:

``` shell
```shell
npm ci
```

## Usage

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

Expand Down
2 changes: 1 addition & 1 deletion connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
.finally(() => client.disconnect());
10 changes: 5 additions & 5 deletions create-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
};

Expand All @@ -31,4 +31,4 @@ createWallet()
client.on('error', (error, context) => {
console.error(`Client error: ${error.name}`);
console.error(context);
});
});
2 changes: 1 addition & 1 deletion send-funds.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ sendFunds()
client.on('error', (error, context) => {
console.error(`Client error: ${error.name}`);
console.error(context);
});
});
2 changes: 1 addition & 1 deletion use-dapi-client-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
.finally(() => client.disconnect());