Skip to content
2 changes: 1 addition & 1 deletion docs/dapi-client-js/usage/core/broadcasttransaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Parameters:

Returns : transactionId (string).

N.B : The TransactionID provided is subject to [transaction malleability](https://dashcore.readme.io/docs/core-guide-transactions-transaction-malleability), and is not a source of truth (the transaction might be included in a block with a different txid).
N.B : The TransactionID provided is subject to [transaction malleability](https://docs.dash.org/projects/core/en/stable/docs/guide/transactions-transaction-malleability.html), and is not a source of truth (the transaction might be included in a block with a different txid).
14 changes: 14 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ resources/source-code
Previous Version of Docs <https://dashplatform.readme.io/v0.23.0/docs>
```

```{toctree}
:maxdepth: 2
:titlesonly:
:caption: Dash SDK
:hidden:

sdk-js/overview
sdk-js/examples/examples
sdk-js/getting-started/getting-started
sdk-js/platform/platform
sdk-js/usage/usage
sdk-js/wallet/wallet
```

```{toctree}
:maxdepth: 2
:titlesonly:
Expand Down
2 changes: 1 addition & 1 deletion docs/intro/what-is-dash.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ However, the Dash network has a second layer of network participants that provid

### Long-Living Masternode Quorums

Dash's [long-living masternode quorums](https://dashcore.readme.io/docs/core-guide-dash-features-masternode-quorums) (LLMQs) are used to facilitate the operation of masternode-provided features in a decentralized, deterministic way. These LLMQs are deterministic subsets of the overall masternode list that are formed via a [distributed key generation](../reference/glossary.md#distributed-key-generation-dkg) protocol and remain active for long periods of time (e.g. hours to days). The main task of LLMQs is to perform threshold signing of consensus-related messages for features like InstantSend and ChainLocks.
Dash's [long-living masternode quorums](https://docs.dash.org/projects/core/en/stable/docs/guide/dash-features-masternode-quorums.html) (LLMQs) are used to facilitate the operation of masternode-provided features in a decentralized, deterministic way. These LLMQs are deterministic subsets of the overall masternode list that are formed via a [distributed key generation](../reference/glossary.md#distributed-key-generation-dkg) protocol and remain active for long periods of time (e.g. hours to days). The main task of LLMQs is to perform threshold signing of consensus-related messages for features like InstantSend and ChainLocks.

### InstantSend

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/dapi-endpoints-core-grpc-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ GetTransactionResponse {

### subscribeToBlockHeadersWithChainLocks

This endpoint helps support simplified payment verification ([SPV](https://dashcore.readme.io/docs/core-guide-operating-modes-simplified-payment-verification-spv)) via DAPI by providing access to block headers which can then be used to verify transactions and simplified masternode lists.
This endpoint helps support simplified payment verification ([SPV](https://docs.dash.org/projects/core/en/stable/docs/guide/operating-modes-simplified-payment-verification-spv.html)) via DAPI by providing access to block headers which can then be used to verify transactions and simplified masternode lists.

**Returns**: streams the requested block header information
**Parameters**:
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/dapi-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| 1 | [`getStatus`](../reference/dapi-endpoints-core-grpc-endpoints.md#getstatus) | Returns blockchain status information |
| 1 | [`getTransaction`](../reference/dapi-endpoints-core-grpc-endpoints.md#gettransaction) | Returns details for the requested transaction |
| 1 | [`subscribeTo` `BlockHeadersWithChainLocks`](../reference/dapi-endpoints-core-grpc-endpoints.md#subscribetoblockheaderswithchainlocks) | Returns the requested block headers along with the associated ChainLocks.<br>_Added in Dash Platform v0.22_ |
| 1 | [`subscribeTo` `TransactionsWithProofs`](../reference/dapi-endpoints-core-grpc-endpoints.md#subscribetotransactionswithproofs) | Returns transactions matching the provided bloom filter along with the associated [`islock` message](https://dashcore.readme.io/docs/core-ref-p2p-network-instantsend-messages#islock) and [merkle block](https://dashcore.readme.io/docs/core-ref-p2p-network-data-messages#merkleblock) |
| 1 | [`subscribeTo` `TransactionsWithProofs`](../reference/dapi-endpoints-core-grpc-endpoints.md#subscribetotransactionswithproofs) | Returns transactions matching the provided bloom filter along with the associated [`islock` message](https://docs.dash.org/projects/core/en/stable/docs/reference/p2p-network-instantsend-messages.html#islock) and [merkle block](https://docs.dash.org/projects/core/en/stable/docs/reference/p2p-network-data-messages.html#merkleblock) |

### Platform gRPC Service

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ An organization where decision making is governed according to a set of rules th

## Devnet

A development environment in which developers can obtain and spend Dash that has no real-world value on a network that is very similar to the Dash [mainnet](#mainnet). Multiple independent devnets can coexist without interference. Devnets can be either public or private networks. See the <a href="https://dashcore.readme.io/docs/core-examples-testing-applications" target="_blank">Testing Applications page</a> for a more detailed description of network types.
A development environment in which developers can obtain and spend Dash that has no real-world value on a network that is very similar to the Dash [mainnet](#mainnet). Multiple independent devnets can coexist without interference. Devnets can be either public or private networks. See the <a href="https://docs.dash.org/projects/core/en/stable/docs/examples/testing-applications.html" target="_blank">Testing Applications page</a> for a more detailed description of network types.

## Direct Settlement Payment Channel (DSPC)

Expand Down Expand Up @@ -123,7 +123,7 @@ BLS signature resulting from some agreement within a masternode quorum

## Regtest

A local regression testing environment in which developers can almost instantly generate blocks on demand for testing events, and can create private Dash with no real-world value. See the <a href="https://dashcore.readme.io/docs/core-examples-testing-applications" target="_blank">Testing Applications page</a> for a more detailed description of network types.
A local regression testing environment in which developers can almost instantly generate blocks on demand for testing events, and can create private Dash with no real-world value. See the <a href="https://docs.dash.org/projects/core/en/stable/docs/examples/testing-applications.html" target="_blank">Testing Applications page</a> for a more detailed description of network types.

## Simple Payment Verification
A method for verifying if transactions are part of a block without downloading the whole block. This is useful for lightweight clients which don't run continuously and which don't have the storage space or bandwidth for a full copy of the blockchain.
Expand All @@ -142,7 +142,7 @@ Dash fork of [Tendermint](https://tendermint.com/core) modified for use in Dash

## Testnet

A global testing environment in which developers can obtain and spend Dash that has no real-world value on a network that is very similar to the Dash [mainnet](#mainnet). See the <a href="https://dashcore.readme.io/docs/core-examples-testing-applications" target="_blank">Testing Applications page</a> for a more detailed description of network types.
A global testing environment in which developers can obtain and spend Dash that has no real-world value on a network that is very similar to the Dash [mainnet](#mainnet). See the <a href="https://docs.dash.org/projects/core/en/stable/docs/examples/testing-applications.html" target="_blank">Testing Applications page</a> for a more detailed description of network types.

See: [Intro to Testnet](../intro/to-testnet.md) for more information

Expand Down
13 changes: 13 additions & 0 deletions docs/sdk-js/examples/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Examples

```{toctree}
:maxdepth: 2
:titlesonly:

fetch-an-identity-from-its-name
generate-a-new-mnemonic
paying-to-another-address
receive-money-and-check-balance
sign-and-verify-messages
use-different-account
```
17 changes: 17 additions & 0 deletions docs/sdk-js/examples/fetch-an-identity-from-its-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Fetching an identity from its name

Assuming you have created an identity and attached a name to it (see how to [register an identity](../../tutorials/identities-and-names/register-an-identity.md) and how to [attach it to a name](../../tutorials/identities-and-names/register-a-name-for-an-identity.md)), you will then be able to directly recover an identity from its names. See below:

```js
const client = new Dash.Client({
wallet: {
mnemonic: '', // Your app mnemonic, which holds the identity
},
});

// This is the name previously registered in DPNS.
const identityName = 'alice';

const nameDocument = await client.platform.names.resolve(`${identityName}.dash`);
const identity = await client.platform.identities.get(nameDocument.ownerId);
```
48 changes: 48 additions & 0 deletions docs/sdk-js/examples/generate-a-new-mnemonic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generate a new mnemonic

In order to be able to keep your private keys private, we encourage to create your own mnemonic instead of using those from the examples (that might be empty).
Below, you will be proposed two options allowing you to create a new mnemonic, depending on the level of customisation you need.

## Dash.Client

By passing `null` to the mnemonic value of the wallet options, you can get Wallet-lib to generate a new mnemonic for you.

```js
const Dash = require("dash");
const client = new Dash.Client({
network: "testnet",
wallet: {
mnemonic: null,
},
});
const mnemonic = client.wallet.exportWallet();
console.log({mnemonic});
```

## Dash.Mnemonic

```js
const Dash = require("dash");
const {Mnemonic} = Dash.Core;

const mnemnonic = new Mnemonic().toString()
```

### Language selection

```js
const {Mnemonic} = Dash.Core;
const {CHINESE, ENGLISH, FRENCH, ITALIAN, JAPANESE, SPANISH} = Mnemonic.Words;
console.log(new Mnemonic(Mnemonic.Words.FRENCH).toString())
```

### Entropy size

By default, the value for mnemonic is `128` (12 words), but you can generate a 24 words (or other) :

```js
const {Mnemonic} = Dash.Core;
console.log(new Mnemonic(256).toString())
```

You can even replace the word list by your own, providing a list of 2048 unique words.
28 changes: 28 additions & 0 deletions docs/sdk-js/examples/paying-to-another-address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Paying to another address

In order to pay, you need to have an [existing balance](../examples/receive-money-and-check-balance.md).
The below code will allow you to pay to a single address a specific amount of satoshis.

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

const mnemonic = ''; // your mnemonic here.
const client = new Dash.Client({
wallet: {
mnemonic,
},
});

async function payToRecipient(account) {
const transaction = account.createTransaction({
recipient: 'yNPbcFfabtNmmxKdGwhHomdYfVs6gikbPf',
satoshis: 10000,
});
const transactionId = await account.broadcastTransaction(transaction);
}

client.wallet.getAccount().then(payToRecipient);

```

See more on create [transaction options here](https://dashpay.github.io/platform/Wallet-library/account/createTransaction/).
92 changes: 92 additions & 0 deletions docs/sdk-js/examples/receive-money-and-check-balance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Receive money and display balance

## Initialize client

Initialize the SDK Client with your [generated mnemonic](../examples/generate-a-new-mnemonic.md) passed as an option.

```js
const Dash = require("dash");
const mnemonic = ''// your mnemonic here.
const client = new Dash.Client({
wallet: {
mnemonic,
}
});

async function showBalance() {
const account = await client.wallet.getAccount();
const totalBalance = account.getTotalBalance();
console.log(`Account's total balance: ${totalBalance} duffs`);
}
```

Having your `client` instance set up, you will be able to access the `account` and `wallet` instance generated from your mnemonic.

By default `getAccount()` returns the first BIP44 account.
You can read more on [how to use a different account](../examples/use-different-account.md).

## Generate a receiving address

Dash wallet supports two different types of addresses:

- `external` addresses used for receiving funds from other addresses
- `internal` addresses used for change outputs of outgoing transactions
- For your privacy, you might want to generate a new address for each payment:

```js
async function generateUnusedAddress() {
const account = await client.wallet.getAccount();
const { address } = account.getUnusedAddress();
console.log(`Unused external address: ${address}`);
}
```

This above code will generate a new unique (never used) address.

## Displaying your balance

_Dash Wallet returns the balance in duffs (1 Dash is equal to 100.000.000 duffs)_

`getTotalBalance()` function takes into account `confirmed` and `unconfirmed` transactions (not included in a block).
It is recommended to check the confirmed balance before making a payment:

```js
async function showBalance() {
const account = await client.wallet.getAccount();
const totalBalance = account.getTotalBalance();
const confirmedBalance = account.getConfirmedBalance();
const unconfirmedBalance = account.getUnconfirmedBalance();
console.log(`Account balance:
Confirmed: ${confirmedBalance}
Unconfirmed: ${unconfirmedBalance}
Total: ${totalBalance}
`);
}
```

## Listen for event on received transaction

When a new unconfirmed transaction is received, you can receive an event, and then validate the address or perform an action if needed.

```js
// FETCHED/UNCONFIRMED_TRANSACTION event is currently disabled

async function listenUnconfirmedTransaction() {
const account = await client.wallet.getAccount();
account.on('FETCHED/UNCONFIRMED_TRANSACTION', (data) => {
console.dir(data);
});
}
```

## Get address at specific index

In case you want to retrieve an address at specific index:

```js
async function getAddressAtIndex() {
const account = await client.wallet.getAccount();
const { address: externalAddress } = account.getAddress(2);
const { address: internalAddress } = account.getAddress(2, 'internal');
}
```
24 changes: 24 additions & 0 deletions docs/sdk-js/examples/sign-and-verify-messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Sign and verify messages

Dash SDK exports the Message constructor inside the Core namespace `new Dash.Core.Message`

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

const mnemonic = '';

const client = new Dash.Client({
wallet: {
mnemonic,
},
});

async function signAndVerify() {
const account = await client.wallet.getAccount();

const pk = new Dash.Core.PrivateKey();
const message = new Dash.Core.Message('hello, world');
const signed = account.sign(message, pk);
const verified = message.verify(pk.toAddress().toString(), signed.toString());
}
```
11 changes: 11 additions & 0 deletions docs/sdk-js/examples/use-different-account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Using a different account

Clients initialized with a mnemonic support multiple accounts as defined in [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki).

By default `client.wallet.getAccount()` returns the account at index `0`.

To access other accounts, pass the `index` option:

```
const secondAccount = await client.wallet.getAccount({ index: 1 })
```
5 changes: 5 additions & 0 deletions docs/sdk-js/getting-started/about-schemas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# About Schemas

Schemas represents the application data structure, a JSON Schema language based set of rules that allows the creation of a Data Contract.

You can read more in the [Dash Platform Documentation - Data contract section](../../explanations/platform-protocol-data-contract.md).
30 changes: 30 additions & 0 deletions docs/sdk-js/getting-started/core-concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Core concepts

The [Dash Core Developer Guide](https://docs.dash.org/projects/core/en/stable/docs/guide/introduction.html) will answer most of questions about the fundamentals of Dash. However, some elements provided by the SDK need to be grasped, so we will quickly cover some of those.

## Wallet

At the core of Dash is the Payment Chain. In order to be able to transact on it, one needs to have a set of [UTXOs](https://docs.dash.org/projects/core/en/stable/docs/guide/block-chain-transaction-data.html) that are controlled by a Wallet instance.

In order to access your UTXO, you will have to provide a valid mnemonic that will unlock the Wallet and automatically fetch the associated UTXOs.

When an SDK instance is created, you can access your wallet via the `client.wallet` variable. (Check [wallet-lib documentation](https://dashpay.github.io/platform/Wallet-library/) for more details)

## Account

Since the introduction of deterministic wallets ([BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)), a wallet is represented by multiple accounts.

It is the instance you will use most of the time for receiving or broadcasting payments.

You can access your account with `client.getWalletAccount()`. See [how to use a different account](../examples/use-different-account.md) if you need to get an account at a specific index.

## App Schema and Contracts

The Dash Platform Chain provides developers with the ability to create applications.
Each application requires a set of rules and conditions described as a portable document in the form of a JSON Schema.

When registered, those applications schemas are called contracts and contains a contractId (namespace : `client.platform.contracts`).

By default, this library supports Dash Platform Name Service (DPNS) (to attach a name to an identity), under the namespace `client.platform.names` for testnet.

See: [how to use multiple apps](../getting-started/working-with-multiple-apps.md)
9 changes: 9 additions & 0 deletions docs/sdk-js/getting-started/dash-platform-applications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Dash Platform applications

## DPNS

DPNS is handled in the Dash SDK Client under the namespace `client.platform.names.*'`. [Read more here](../platform/names/names.md)

## DashPay

The DashPay contract is registered on testnet under contract id `Bwr4WHCPz5rFVAD87RqTs3izo4zpzwsEdKPWUT1NS1C7`. Its functionality is not incorporated with the Dash SDK at this time.
12 changes: 12 additions & 0 deletions docs/sdk-js/getting-started/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Getting started

```{toctree}
:maxdepth: 2

about-schemas
core-concepts
dash-platform-applications
working-with-multiple-apps
quick-start
with-typescript
```
Loading