Skip to content

Commit

Permalink
feat(js-dash-sdk): add NFT state transitions docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic committed Jan 31, 2025
1 parent dbf1b7c commit 1207597
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/js-dash-sdk/docs/platform/documents/broadcast.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

Parameters:

| parameters | type | required | Description |
|----------------------------|------------|----------|------------------------------------------------------------------------------|
| **documents** | Object | yes | |
| **documents.create** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to create |
| **documents.replace** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to replace |
| **documents.delete** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to delete |
| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) |
| parameters | type | required | Description |
|---------------------------|--------------------|----------|----------------------------------------------------------------------------------------|
| **documents** | Object | yes | |
| **documents.create** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to create |
| **documents.replace** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to replace |
| **documents.delete** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to delete |
| **documents.transfer** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to transfer |
| **documents.updatePrice** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to set price |
| **documents.purchase** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to purchase |
| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) |
| **options** | DocumentTransitionParams | no | An object with two optional fields `price` and `receiver` that is used for NFT actions |


**Example**:
Expand Down
33 changes: 33 additions & 0 deletions packages/js-dash-sdk/docs/platform/documents/purchase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
**Usage**: `client.platform.documents.broadcast(documents, identity, options)`
**Description**: This method will broadcast a purchase state transition that buys the given document from other Identity.

Parameters:

| parameters | type | required | Description |
|------------------------|---------|------------------ |-------------------------------------------------------------------|
| **documents.purchase** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to buy |
| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) |
| **options** | DocumentTransitionParams | no | An object with field `price` (BigInt) and `receiver` (Identifier) |

**Example**:
```js
const identityId = '';// Your identity identifier
const receiverId = ''; // Receiver identity identifier
const documentId = '' // Your document id
const price = BigInt(1000000)

const identity = await client.platform.identities.get(identityId);
const receiverIdentity = await client.platform.identities.get(receiverId);

const identity = await client.platform.identities.get(identityId);

const [document] = await dash.platform.documents.get(
'helloWorldContract.note',
{ where: [['$id', '==', documentId]] },
);

await dash.platform.documents.broadcast({ updatePrice: [document], }, identity, { price, receiver: receiverIdentity.getId() });
```
**Note**: This method will change the ownership of the document to your identity, and seller identity will be credited with the amount specified in the updatePrice deducted from your balance.

Returns: DocumentsBatchTransition
31 changes: 31 additions & 0 deletions packages/js-dash-sdk/docs/platform/documents/transfer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
**Usage**: `client.platform.documents.broadcast(documents, identity, options)`
**Description**: This method will broadcast a document transfer

Parameters:

| parameters | type | required | Description |
|-------------------|---------|------------------ |-----------------------------------------------------------------------|
| **documents.transfer** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to transfer |
| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) |
| **options** | DocumentTransitionParams | no | An object with `receiver` field |

**Example**:
```js
const identityId = '';// Your identity identifier
const receiverId = ''; // Receiver identity identifier
const documentId = '' // Your document id

const identity = await client.platform.identities.get(identityId);
const receiverIdentity = await client.platform.identities.get(receiverId);

const [document] = await dash.platform.documents.get(
'helloWorldContract.note',
{ where: [['$id', '==', documentId]] },
);

await dash.platform.documents.broadcast({ transfer: [document], }, identity, { receiver: receiverIdentity.getId() });
```

**Note**: Transfer transition changes the ownership of the given document to the receiver identity

Returns: DocumentsBatchTransition
29 changes: 29 additions & 0 deletions packages/js-dash-sdk/docs/platform/documents/updatePrice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
**Usage**: `client.platform.documents.broadcast(documents, identity, options)`
**Description**: This method will broadcast an update price state transition that sets a price for the given document.

Parameters:

| parameters | type | required | Description |
|---------------------------|---------|------------------ |---------------------------------------------------------------------------|
| **documents.updatePrice** | ExtendedDocument[] | no | array of valid [created document](../documents/create.md) to update price |
| **identity** | Identity | yes | A valid [registered identity](../identities/register.md) |
| **options** | DocumentTransitionParams | no | An object with field `price` (BigInt) |

**Example**:
```js
const identityId = '';// Your identity identifier
const documentId = '' // Your document id
const price = BigInt(1000000)

const identity = await client.platform.identities.get(identityId);

const [document] = await dash.platform.documents.get(
'helloWorldContract.note',
{ where: [['$id', '==', documentId]] },
);

await dash.platform.documents.broadcast({ updatePrice: [document], }, identity, { price });
```
**Note**: This method sets the same price on all documents in the batch (only one is possible right now)

Returns: DocumentsBatchTransition

0 comments on commit 1207597

Please sign in to comment.