Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.exe
_build
**/.DS_Store
.local/
.vscode
4 changes: 3 additions & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
'.DS_Store',
'README.md',
'.devcontainer',
'local',
'scripts',
'img/dev/gifs/README.md',
'docs/other',
'docs/ai-prompt.md'
'docs/ai-prompt.md',
'platform-src'
]

# The master toctree document.
Expand Down
96 changes: 31 additions & 65 deletions docs/tutorials/connecting-to-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The purpose of this tutorial is to walk through the steps necessary to access th

## Overview

Platform services are provided via a combination of HTTP and gRPC connections to DAPI, and some connections to an Insight API. Although one could interact with DAPI by connecting to these directly, or by using [DAPI-client](https://github.com/dashpay/platform/tree/master/packages/js-dapi-client), the easiest approach is to use the [JavaScript Dash SDK](https://github.com/dashpay/platform/tree/master/packages/js-dash-sdk).
Platform services are provided via a combination of HTTP and gRPC connections to DAPI. The easiest approach is to use the [Dash Evo SDK](https://www.npmjs.com/package/@dashevo/evo-sdk), which handles connection management automatically.

## Prerequisites

Expand All @@ -18,94 +18,60 @@ Platform services are provided via a combination of HTTP and gRPC connections to

### 1. Install the Dash SDK

The JavaScript SDK package is available from npmjs.com and can be installed by running `npm install dash` from the command line:
The JavaScript SDK package is available from npmjs.com and can be installed by running `npm install @dashevo/evo-sdk` from the command line:

```shell
npm install dash
npm install @dashevo/evo-sdk
```

### 2. Connect to Dash Platform

:::{tip}
The JavaScript Dash SDK connects to mainnet by default. To connect to other networks,
set the `network` option when instantiating the client as shown in the following example.
:::

Create a file named `dashConnect.js` with the following contents. Then run it by typing `node dashConnect.js` from the command line:
Create a file named `dashConnect.mjs` with the following contents. Then run it by typing `node dashConnect.mjs` from the command line:

```javascript dashConnect.js
const Dash = require('dash');
```{code-block} javascript
:caption: dashConnect.mjs

const client = new Dash.Client({ network: 'testnet' });
import { EvoSDK } from '@dashevo/evo-sdk';

async function connect() {
return await client.getDAPIClient().core.getBestBlockHash();
try {
const sdk = EvoSDK.testnetTrusted();
await sdk.connect();
const status = await sdk.system.status();
console.log('Connected. System status:\n', status.toJSON());
} catch (e) {
console.error('Failed to fetch system status:', e.message);
}

connect()
.then((d) => console.log('Connected. Best block hash:\n', d))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
```

Once this returns successfully, you're ready to begin developing! See the [Quickstart](../tutorials/introduction.md#quickstart) for recommended next steps. For details on all SDK options and methods, please refer to the [SDK documentation](../sdk-js/overview.md).

## Connect to a Devnet
Once this returns successfully, you're ready to begin developing! See the [Quickstart](../tutorials/introduction.md#quickstart) for recommended next steps. For details on SDK methods, please refer to the [SDK documentation](https://dashpay.github.io/evo-sdk-website/docs.html).

The SDK also supports connecting to development networks (devnets). Since devnets can be created by anyone, the client library will be unaware of them unless connection information is provided using one of the options described below.
## Connect to a Local Devnet

### Connect via Seed
The SDK supports connecting to a local development network managed by [dashmate](https://github.com/dashpay/platform/tree/master/packages/dashmate). The `local` factory methods expect a dashmate-managed environment with a quorum sidecar running at `127.0.0.1:2444`.

Using a seed node is the preferred method in most cases. The client uses the provided seed node to a retrieve a list of available masternodes on the network so requests can be spread across the entire network.
```{code-block} javascript
:caption: localConnect.mjs

```javascript
const Dash = require('dash');
import { EvoSDK } from '@dashevo/evo-sdk';

const client = new Dash.Client({
network: 'testnet',
seeds: [{
host: 'seed-1.testnet.networks.dash.org:1443',
}],
});

async function connect() {
return await client.getDAPIClient().core.getBestBlockHash();
try {
const sdk = EvoSDK.localTrusted();
await sdk.connect();
const status = await sdk.system.status();
console.log('Connected. System status:\n', status.toJSON());
} catch (e) {
console.error('Failed to fetch system status:', e.message);
}

connect()
.then((d) => console.log('Connected. Best block hash:\n', d))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
```

### Connect via Address

Custom addresses may be directly specified via `dapiAddresses` in cases where it is beneficial to know exactly what node(s) are being accessed (e.g. debugging, local development, etc.).

```javascript
const Dash = require('dash');

const client = new Dash.Client({
dapiAddresses: [
'127.0.0.1:3000:3010',
'127.0.0.2:3000:3010',
],
});

async function connect() {
return await client.getDAPIClient().core.getBestBlockHash();
}

connect()
.then((d) => console.log('Connected. Best block hash:\n', d))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
```
:::{note}
The WASM-based SDK currently only supports connecting to known networks (testnet, mainnet, local) via the built-in factory methods. Connecting to remote devnets with custom addresses is not yet supported.
:::

## Connect Directly to DAPI (Optional)

:::{attention}
Normally, the Dash SDK, dapi-client, or another library should be used to interact with DAPI. Connecting directly may be helpful for debugging in some cases, but generally is not required.
Normally, the Dash SDK or another library should be used to interact with DAPI. Connecting directly may be helpful for debugging in some cases, but generally is not required.
:::

The example below demonstrates retrieving the hash of the best block hash directly from a DAPI node via command line and several languages:
Expand Down
79 changes: 41 additions & 38 deletions docs/tutorials/contracts-and-documents/delete-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,60 @@

# Delete documents

In this tutorial we will update delete data from Dash Platform. Data is stored in the form of [documents](../../explanations/platform-protocol-document.md) which are encapsulated in a [state transition](../../explanations/platform-protocol-state-transition.md) before being submitted to DAPI.
In this tutorial we will delete data from Dash Platform. Data is stored in the form of [documents](../../explanations/platform-protocol-document.md) which are encapsulated in a [state transition](../../explanations/platform-protocol-state-transition.md) before being submitted to DAPI.

## Prerequisites

- [General prerequisites](../../tutorials/introduction.md#prerequisites) (Node.js / Dash SDK installed)
- A wallet mnemonic with some funds in it: [Tutorial: Create and Fund a Wallet](../../tutorials/create-and-fund-a-wallet.md)
- A platform address with a balance: [Tutorial: Create and Fund a Wallet](../../tutorials/create-and-fund-a-wallet.md)
- A configured client: [Setup SDK Client](../setup-sdk-client.md)
- Access to a previously created document (e.g., one created using the [Submit Documents tutorial](../../tutorials/contracts-and-documents/submit-documents.md))
- A Dash Platform Identity: [Tutorial: Register an Identity](../../tutorials/identities-and-names/register-an-identity.md)
- (Optional) A Dash Platform Contract ID: [Tutorial: Register a Data Contract](../../tutorials/contracts-and-documents/register-a-data-contract.md) — a default testnet tutorial contract is provided
- An existing document (e.g., one created using the [Submit Documents tutorial](../../tutorials/contracts-and-documents/submit-documents.md))

## Code

```javascript
const setupDashClient = require('../setupDashClient');

const client = setupDashClient();

const deleteNoteDocument = async () => {
const { platform } = client;
const identity = await platform.identities.get('an identity ID goes here');
const documentId = 'an existing document ID goes here';

// Retrieve the existing document
const [document] = await client.platform.documents.get(
'tutorialContract.note',
{ where: [['$id', '==', documentId]] },
);

// Sign and submit the document delete transition
await platform.documents.broadcast({ delete: [document] }, identity);
return document;
};

deleteNoteDocument()
.then((d) => console.log('Document deleted:\n', d.toJSON()))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
```{code-block} javascript
:caption: deleteDocument.mjs

import { setupDashClient } from '../setupDashClient.mjs';

const { sdk, keyManager } = await setupDashClient();
const { identity, identityKey, signer } = await keyManager.getAuth();

// Default tutorial contract (testnet). Replace or override via DATA_CONTRACT_ID.
const DATA_CONTRACT_ID =
process.env.DATA_CONTRACT_ID ??
'FW3DHrQiG24VqzPY4ARenMgjEPpBNuEQTZckV8hbVCG4';

// Replace with your existing document ID
const DOCUMENT_ID = 'YOUR_DOCUMENT_ID';

try {
// Delete the document from the platform
await sdk.documents.delete({
document: {
id: DOCUMENT_ID,
ownerId: identity.id,
dataContractId: DATA_CONTRACT_ID,
documentTypeName: 'note',
},
identityKey,
signer,
});

console.log('Document deleted successfully');
} catch (e) {
console.error('Something went wrong:\n', e.message);
}
```

:::{tip}
The example above shows how access to contract documents via `<contract name>.<contract document>` syntax (e.g. `tutorialContract.note`) can be enabled by passing a contract identity to the constructor. Please refer to the [Dash SDK documentation](https://github.com/dashpay/platform/blob/master/packages/js-dash-sdk/docs/getting-started/multiple-apps.md) for details.
:::

## What's happening

After we initialize the Client, we retrieve the document to be deleted via `platform.documents.get` using its `id`.

Once the document has been retrieved, we must submit it to [DAPI](../../explanations/dapi.md). Documents are submitted in batches that may contain multiple documents to be created, replaced, or deleted. In this example, a single document is being deleted.
After we initialize the client, we get the auth key signer from the key manager. We then call `sdk.documents.delete()` with an object identifying the document to delete — its `id`, `ownerId`, `dataContractId`, and `documentTypeName` — along with the signing credentials.

The `platform.documents.broadcast` method takes the document batch (e.g. `{delete: [documents[0]]}`) and an identity parameter. Internally, it creates a [State Transition](../../explanations/platform-protocol-state-transition.md) containing the previously created document, signs the state transition, and submits the signed state transition to DAPI.
Internally, the method creates a [State Transition](../../explanations/platform-protocol-state-transition.md) containing the document deletion instruction, signs the state transition, and submits it to DAPI. Only the document's owner can delete it.

:::{note}
:class: note
Since the SDK does not cache wallet information, lengthy re-syncs (5+ minutes) may be required for some Core chain wallet operations. See [Wallet Operations](../setup-sdk-client.md#wallet-operations) for options.
You do not need to retrieve the full document before deleting it. The `sdk.documents.delete()` method only requires the document's identifying fields (`id`, `ownerId`, `dataContractId`, `documentTypeName`).
:::
Loading