Skip to content

Commit 5bb2b69

Browse files
committed
docs(tutorials): migrate send funds tutorial to evo sdk
Update tutorial sync mapping to include this tutorial now
1 parent 6c6911e commit 5bb2b69

2 files changed

Lines changed: 54 additions & 38 deletions

File tree

docs/tutorials/send-funds.md

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,56 @@
44

55
# Send funds
66

7-
Once you have a wallet and some funds ([tutorial](../tutorials/create-and-fund-a-wallet.md)), another common task is sending Dash to an address. (Sending Dash to a contact or a DPNS identity requires the Dashpay app, which has not been registered yet.)
8-
9-
# Code
10-
11-
:::{note}
12-
:class: note
13-
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.
14-
:::
15-
16-
```javascript
17-
const setupDashClient = require('../setupDashClient');
18-
19-
const client = setupDashClient();
20-
21-
const sendFunds = async () => {
22-
const account = await client.getWalletAccount();
23-
24-
const transaction = account.createTransaction({
25-
recipient: 'yP8A3cbdxRtLRduy5mXDsBnJtMzHWs6ZXr', // Testnet2 faucet
26-
satoshis: 100000000, // 1 Dash
7+
The purpose of this tutorial is to walk through the steps necessary to transfer credits from one platform address to another. Platform addresses are bech32m-encoded addresses used for Dash Platform operations.
8+
9+
## Prerequisites
10+
11+
- [General prerequisites](../tutorials/introduction.md#prerequisites) (Node.js / Dash SDK installed)
12+
- A platform address with a balance: [Tutorial: Create and Fund a Wallet](../tutorials/create-and-fund-a-wallet.md)
13+
- A configured client: [Setup SDK Client](./setup-sdk-client.md)
14+
15+
## Code
16+
17+
```{code-block} javascript
18+
:caption: send-funds.mjs
19+
20+
import { setupDashClient } from './setupDashClient.mjs';
21+
22+
const { sdk, addressKeyManager } = await setupDashClient();
23+
const signer = addressKeyManager.getSigner();
24+
25+
const recipient =
26+
process.env.RECIPIENT_PLATFORM_ADDRESS ||
27+
'tdash1kr2ygqnqvsms509f78t4v3uqmce2re22jqycaxh4';
28+
const amount = 500000n; // 0.000005 DASH
29+
30+
try {
31+
const result = await sdk.addresses.transfer({
32+
inputs: [
33+
{
34+
address: addressKeyManager.primaryAddress.bech32m,
35+
amount,
36+
},
37+
],
38+
outputs: [
39+
{
40+
address: recipient,
41+
amount,
42+
},
43+
],
44+
signer,
2745
});
28-
return account.broadcastTransaction(transaction);
29-
};
30-
31-
sendFunds()
32-
.then((d) => console.log('Transaction broadcast!\nTransaction ID:', d))
33-
.catch((e) => console.error('Something went wrong:\n', e))
34-
.finally(() => client.disconnect());
35-
36-
// Handle wallet async errors
37-
client.on('error', (error, context) => {
38-
console.error(`Client error: ${error.name}`);
39-
console.error(context);
40-
});
46+
console.log(`Transaction broadcast! Sent ${amount} credits to ${recipient}`);
47+
for (const [address, info] of result) {
48+
const addr =
49+
typeof address === 'string' ? address : address.toBech32m('testnet');
50+
console.log(` ${addr}: ${info.balance} credits (nonce: ${info.nonce})`);
51+
}
52+
} catch (e) {
53+
console.error('Something went wrong:\n', e.message);
54+
}
4155
```
4256

43-
# What's Happening
57+
## What's Happening
4458

45-
After initializing the Client, we build a new transaction with `account.createTransaction`. It requires a recipient and an amount in satoshis (often called "duffs" in Dash). 100 million satoshis equals one Dash. We pass the transaction to `account.broadcastTransaction` and wait for it to return. Then we output the result, which is a transaction ID. After that we disconnect from the Client so node can exit.
59+
After we initialize the Client via `setupDashClient()`, we get a signer from the `addressKeyManager`. We then call `sdk.addresses.transfer()` with `inputs` (the sender's address and amount to debit) and `outputs` (the recipient's address and amount to credit), along with the signer.

scripts/tutorial-sync/tutorial-code-map.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ mappings:
2323
block_id:
2424
caption: create-wallet.mjs
2525

26+
- source: send-funds.mjs
27+
doc: send-funds.md
28+
block_id:
29+
caption: send-funds.mjs
30+
2631
- source: setupDashClient.mjs
2732
doc: setup-sdk-client.md
2833
block_id:
2934
caption: setupDashClient.mjs
3035

31-
# send-funds.md excluded: source file uses old CommonJS SDK,
32-
# docs already migrated to Evo SDK. Add when platform-tutorials updates.
33-
3436
# -- Identities and Names --
3537

3638
- source: 1-Identities-and-Names/identity-register.mjs

0 commit comments

Comments
 (0)