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
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ tutorials/setup-sdk-client
tutorials/identities-and-names
tutorials/contracts-and-documents
tutorials/send-funds
tutorials/use-dapi-client-methods
tutorials/setup-a-node
tutorials/tui/index
tutorials/building-platform
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/connecting-to-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ npm install @dashevo/evo-sdk

### 2. Connect to Dash Platform

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

```{code-block} javascript
:caption: dashConnect.mjs
:caption: connect.mjs

import { EvoSDK } from '@dashevo/evo-sdk';

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/contracts-and-documents/delete-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In this tutorial we will delete data from Dash Platform. Data is stored in the f
## Code

```{code-block} javascript
:caption: deleteDocument.mjs
:caption: document-delete.mjs

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,13 @@ const { identity, identityKey, signer } = await keyManager.getAuth();
const documentSchemas = {
note: {
type: 'object',
indices: [{
name: 'ownerId',
properties: [{ $ownerId: 'asc' }],
unique: false,
}],
indices: [
{
name: 'ownerId',
properties: [{ $ownerId: 'asc' }],
unique: false,
},
],
properties: {
message: {
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In this tutorial we will retrieve the data contract created in the [Register a D
## Code

```{code-block} javascript
:caption: retrieveContract.mjs
:caption: contract-retrieve.mjs

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ information.
## Code

```{code-block} javascript
:caption: retrieveContractHistory.mjs
:caption: contract-retrieve-history.mjs

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In this tutorial we will retrieve some of the current data from a data contract.
## Code

```{code-block} javascript
:caption: getDocuments.mjs
:caption: document-retrieve.mjs

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

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/contracts-and-documents/submit-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In this tutorial we will submit some data to an application on Dash Platform. Da
## Code

```{code-block} javascript
:caption: submitDocument.mjs
:caption: document-submit.mjs

import { Document } from '@dashevo/evo-sdk';
import { setupDashClient } from '../setupDashClient.mjs';
Expand Down
14 changes: 8 additions & 6 deletions docs/tutorials/contracts-and-documents/update-a-data-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ const { identityKey, signer } = await keyManager.getAuth();
// Edit these values for your environment
// Your contract ID from the Register a Data Contract tutorial
const DATA_CONTRACT_ID =
process.env.DATA_CONTRACT_ID ??
'YOUR_DATA_CONTRACT_ID';
process.env.DATA_CONTRACT_ID ?? 'YOUR_DATA_CONTRACT_ID';
const DOCUMENT_TYPE = 'note';

if (!DATA_CONTRACT_ID || DATA_CONTRACT_ID === 'YOUR_DATA_CONTRACT_ID') {
throw new Error('Set DATA_CONTRACT_ID (env var or in code) to your contract ID from the Register a Data Contract tutorial');
throw new Error(
'Set DATA_CONTRACT_ID (env var or in code) to your contract ID from the Register a Data Contract tutorial',
);
}

try {
Expand Down Expand Up @@ -86,12 +87,13 @@ const { identityKey, signer } = await keyManager.getAuth();
// Edit these values for your environment
// Your contract ID from the Register a Data Contract tutorial
const DATA_CONTRACT_ID =
process.env.DATA_CONTRACT_ID ??
'YOUR_DATA_CONTRACT_ID';
process.env.DATA_CONTRACT_ID ?? 'YOUR_DATA_CONTRACT_ID';
const DOCUMENT_TYPE = 'note';

if (!DATA_CONTRACT_ID || DATA_CONTRACT_ID === 'YOUR_DATA_CONTRACT_ID') {
throw new Error('Set DATA_CONTRACT_ID (env var or in code) to your contract ID from the Register a Data Contract tutorial');
throw new Error(
'Set DATA_CONTRACT_ID (env var or in code) to your contract ID from the Register a Data Contract tutorial',
);
}

try {
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/contracts-and-documents/update-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In this tutorial we will update existing data on Dash Platform. Data is stored i
## Code

```{code-block} javascript
:caption: updateDocument.mjs
:caption: document-update.mjs

import { Document } from '@dashevo/evo-sdk';
import { setupDashClient } from '../setupDashClient.mjs';
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/create-and-fund-a-wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In order to make create an identity on Dash Platform, you need a platform addres
# Code

```{code-block} javascript
:caption: generateWallet.mjs
:caption: create-wallet.mjs

import { wallet, PlatformAddressSigner, PrivateKey } from '@dashevo/evo-sdk';

Expand Down
1 change: 0 additions & 1 deletion docs/tutorials/identities-and-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ identities-and-names/retrieve-an-identity
identities-and-names/topup-an-identity-balance
identities-and-names/withdraw-an-identity-balance
identities-and-names/update-an-identity
identities-and-names/retrieve-an-accounts-identities
identities-and-names/transfer-credits-to-an-identity
identities-and-names/register-a-name-for-an-identity
identities-and-names/retrieve-a-name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Pass only the label (e.g., `myname`), not the full domain name. The `.dash` suff
:::

```{code-block} javascript
:caption: registerName.mjs
:caption: name-register.mjs

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

Expand All @@ -47,7 +47,9 @@ try {
console.log('Name registered:\n', result.toJSON());
} catch (e) {
if (e.message?.includes('duplicate unique properties')) {
console.error(`Name "${NAME_LABEL}.dash" is already registered. Try a different name.`);
console.error(
`Name "${NAME_LABEL}.dash" is already registered. Try a different name.`,
);
} else {
console.error('Something went wrong:\n', e.message);
}
Expand Down
21 changes: 14 additions & 7 deletions docs/tutorials/identities-and-names/register-an-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ Identities serve as the basis for interactions with Dash Platform. They consist
## Code

```{code-block} javascript
:caption: registerIdentity.mjs
:caption: identity-register.mjs

import { randomBytes } from 'node:crypto';
import { Identity, Identifier } from '@dashevo/evo-sdk';
import { setupDashClient } from '../setupDashClient.mjs';

const { sdk, keyManager, addressKeyManager } = await setupDashClient({ requireIdentity: false });
const { sdk, keyManager, addressKeyManager } = await setupDashClient({
requireIdentity: false,
});

try {
// Build the identity shell with 5 standard public keys
Expand All @@ -37,15 +39,20 @@ try {
// Create the identity on-chain, funded from the platform address
const result = await sdk.addresses.createIdentity({
identity,
inputs: [{
address: addressKeyManager.primaryAddress.bech32m,
amount: 5000000n, // Credits to fund the new identity
}],
inputs: [
{
address: addressKeyManager.primaryAddress.bech32m,
amount: 5000000n, // Credits to fund the new identity
},
],
identitySigner: keyManager.getFullSigner(),
addressSigner: addressKeyManager.getSigner(),
});

console.log('Identity registered!\nIdentity ID:', result.identity.id.toString());
console.log(
'Identity registered!\nIdentity ID:',
result.identity.id.toString(),
);
} catch (e) {
// Known SDK bug: proof verification fails but the identity was created
// Issue: https://github.com/dashpay/platform/issues/3095
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/identities-and-names/retrieve-a-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In this tutorial we will retrieve the name created in the [Register a Name for a
:::{tab-item} Resolve by Name

```{code-block} javascript
:caption: resolve-by-name.mjs
:caption: name-resolve-by-name.mjs

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

Expand Down Expand Up @@ -45,7 +45,7 @@ Identity ID for "quantumexplorer.dash": BNnn19SAJZuvsUu787dMzPDXASwuCrm4yQ864tEp
:::{tab-item} Get Identity Names

```{code-block} javascript
:caption: get-identity-names.mjs
:caption: name-get-identity-names.mjs

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

Expand Down Expand Up @@ -78,7 +78,7 @@ Name(s) retrieved for GgZekwh38XcWQTyWWWvmw6CEYFnLU7yiZFPWZEjqKHit:
:::{tab-item} Search for Name

```{code-block} javascript
:caption: search-by-name.mjs
:caption: name-search-by-name.mjs

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

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In this tutorial we will retrieve the identity created in the [Register an Ident
## Code

```{code-block} javascript
:caption: retrieveIdentity.mjs
:caption: identity-retrieve.mjs

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

Expand Down
62 changes: 34 additions & 28 deletions docs/tutorials/identities-and-names/topup-an-identity-balance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,55 @@

# Topup an identity's balance

:::{attention}
This tutorial has not been migrated to use the latest Dash SDK yet and is out-of-date.
:::

The purpose of this tutorial is to walk through the steps necessary to add credits to an identity's balance.

## Overview

As users interact with Dash Platform applications, the credit balance associated with their identity will decrease. Eventually it will be necessary to topup the balance by converting some Dash to credits. Additional details regarding credits can be found in the [Credits description](../../explanations/identity.md#credits).
As users interact with Dash Platform applications, the credit balance associated with their identity will decrease. Eventually it will be necessary to top up the balance by transferring credits from a funded platform address. Additional details regarding credits can be found in the [Credits description](../../explanations/identity.md#credits).

## 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)
- A Dash Platform Identity: [Tutorial: Register an Identity](../../tutorials/identities-and-names/register-an-identity.md)

## Code

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

const client = setupDashClient();

const topupIdentity = async () => {
const identityId = 'an identity ID goes here';
const topUpAmount = 100000; // Number of duffs

await client.platform.identities.topUp(identityId, topUpAmount);
return client.platform.identities.get(identityId);
};

topupIdentity()
.then((d) => console.log('Identity credit balance: ', d.balance))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
```{code-block} javascript
:caption: identity-topup.mjs

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

const { sdk, addressKeyManager, keyManager } = await setupDashClient();
const signer = addressKeyManager.getSigner();

try {
// Identity ID from the identity create tutorial
const IDENTITY_ID = keyManager.identityId;
const identity = await sdk.identities.fetch(IDENTITY_ID);

const result = await sdk.addresses.topUpIdentity({
identity,
inputs: [
{
address: addressKeyManager.primaryAddress.bech32m,
amount: 200000n, // Credits to transfer
},
],
signer,
});

console.log(`Top-up result:
Start balance: ${identity.toJSON().balance}
Final balance: ${result.newBalance}`);
} catch (e) {
console.error('Something went wrong:\n', e.message);
}
```

## What's Happening

After connecting to the Client, we call `platform.identities.topUp` with an identity ID and a topup amount in duffs (1 duff = 1000 credits). This creates a lock transaction and increases the identity's credit balance by the relevant amount (minus fee). The updated balance is output to the console.
After connecting to the client, we get the address signer from the address key manager and fetch the identity to top up using its ID from the key manager.

:::{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.
:::
We then call `sdk.addresses.topUpIdentity()` with the identity, the source platform address, the amount of credits to transfer, and the signer to authorize the transfer. The start and final balances are logged to confirm the top-up succeeded.
Loading