-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update tutorials for v1.4 (#82)
* docs: update tutorials to continue connecting to testnet Platform v1.4 SDK will connect to mainnet by default instead of testnet so the network option has been set to continue using testnet * docs: add credit withdraw tutorial * chore: rename file and add tutorial to sidebar * chore: small updates
- Loading branch information
Showing
6 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
docs/tutorials/identities-and-names/withdraw-an-identity-balance.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
```{eval-rst} | ||
.. tutorials-withdraw-identity-balance: | ||
``` | ||
|
||
:::{attention} | ||
Mainnet withdrawals will not be available until the activation of Dash Platform v1.4 on mainnet in late October or early November. They are already available on testnet. | ||
::: | ||
|
||
# Withdraw an Identity's balance | ||
|
||
The purpose of this tutorial is to walk through the steps necessary to withdraw part of their identity's balance from Platform to a Dash address. | ||
|
||
## Overview | ||
|
||
Over time, users may want to convert some of their identity's [Platform credits](../../explanations/identity.md#credits) back to Dash for use on the Core chain. | ||
|
||
## 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 configured client: [Setup SDK Client](../setup-sdk-client.md) | ||
- A Dash Platform Identity with a credit balance: [Tutorial: Register an Identity](../../tutorials/identities-and-names/register-an-identity.md) | ||
- A Core chain address to receive the withdrawn credits as Dash | ||
|
||
## Code | ||
|
||
```javascript | ||
const setupDashClient = require('../setupDashClient'); | ||
|
||
const client = setupDashClient(); | ||
|
||
const withdrawCredits = async () => { | ||
const identityId = 'an identity ID goes here'; | ||
const identity = await client.platform.identities.get(identityId); | ||
|
||
console.log('Identity balance before transfer: ', identity.balance); | ||
|
||
const toAddress = 'a Dash address goes here'; | ||
const amount = 1000000; // Number of credits to withdraw | ||
const amountDash = amount / (1000 * 100000000); | ||
|
||
console.log(`Withdrawing ${amount} credits (${amountDash} DASH)`); | ||
// Temporarily force minRelay to have a value so withdrawal succeeds | ||
// https://github.com/dashpay/platform/issues/2233 | ||
client.wallet.storage.getDefaultChainStore().state.fees.minRelay = 1000; | ||
|
||
const response = await client.platform.identities.withdrawCredits( | ||
identity, | ||
amount, | ||
{ | ||
toAddress, | ||
}, | ||
); | ||
return client.platform.identities.get(identityId); | ||
}; | ||
|
||
withdrawCredits() | ||
.then((d) => console.log('Identity balance after withdrawal: ', d.balance)) | ||
.catch((e) => console.error('Something went wrong:\n', e)) | ||
.finally(() => client.disconnect()); | ||
``` | ||
|
||
## What's Happening | ||
|
||
After connecting to the Client, we get an identity and set the withdrawal address and amount. We then call `platform.identities.withdrawCredits` with the identity, withdrawal amount in credits, and the destination address. This creates an unlock transaction and decreases the identity's credit balance by the relevant amount including a fee. The updated identity balance is output to the console. Once the withdrawal is processed, it is broadcast to the Core chain where the unlocked Dash is sent to the provided destination address. | ||
|
||
:::{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. | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters