Skip to content

Commit d89fdc7

Browse files
committed
Add minor improvements for javascript code walkthrough
1 parent 01ed305 commit d89fdc7

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

_code-samples/get-started/js/get-acct-info.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// @chunk {"steps": ["import-node-tag"]}
12
// Import the library
2-
// @chunk {"steps": ["connect-tag"]}
33
import xrpl from "xrpl"
4+
// @chunk-end
45

6+
// @chunk {"steps": ["connect-tag"]}
57
// Define the network client
68
const SERVER_URL = "wss://s.altnet.rippletest.net:51233/"
79
const client = new xrpl.Client(SERVER_URL)

docs/tutorials/javascript/build-apps/get-started.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ Click **Download** on the top right of the code preview panel to download the so
6262

6363
Follow the steps to create a simple application with `xrpl.js`.
6464

65-
### 1. Install Dependencies
66-
6765
<!-- Web steps -->
6866
{% step id="import-web-tag" when={ "environment": "Web" } %}
67+
### 1. Install Dependencies
68+
6969
To load `xrpl.js` into your project, add a `<script>` tag to your HTML.
7070

7171
You can load the library from a CDN as in the example, or download a release and host it on your own website.
@@ -74,7 +74,8 @@ This loads the module into the top level as `xrpl`.
7474
{% /step %}
7575

7676
<!-- Node.js steps -->
77-
{% step id="install-node-tag" when={ "environment": "Node" } %}
77+
{% step id="import-node-tag" when={ "environment": "Node" } %}
78+
### 1. Install Dependencies
7879

7980
Start a new project by creating an empty folder, then move into that folder and use [NPM](https://www.npmjs.com/) to install the latest version of xrpl.js:
8081

@@ -94,7 +95,7 @@ Your `package.json` file should look something like this:
9495
{% step id="connect-tag" %}
9596
#### Connect to the XRP Ledger Testnet
9697

97-
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `xrpl.js`, you create an instance of the `Client` class and use the `connect()` method.
98+
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `xrpl.js`, you create an instance of the [`Client`](https://js.xrpl.org/classes/Client.html) class and use the [`connect()`](https://js.xrpl.org/classes/Client.html#connect) method.
9899

99100
{% admonition type="success" name="Tip" %}Many network functions in `xrpl.js` use [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to return values asynchronously. The code samples here use the [`async/await` pattern](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await) to wait for the actual result of the Promises.{% /admonition %}
100101

@@ -130,46 +131,48 @@ The sample code shows you how to connect to the Testnet, which is one of the ava
130131
{% step id="get-account-create-wallet-tag" %}
131132
#### Create and Fund a Wallet
132133

133-
The `xrpl.js` library has a `Wallet` class for handling the keys and address of an XRP Ledger account. On Testnet, you can fund a new account as shown in the example.
134+
The `xrpl.js` library has a [`Wallet`](https://js.xrpl.org/classes/Wallet.html) class for handling the keys and address of an XRP Ledger account. On Testnet, you can fund a new account as shown in the example.
134135
{% /step %}
135136

136137
{% step id="get-account-create-wallet-b-tag" %}
137138
#### (Optional) Generate a Wallet Only
138139

139-
If you want to generate a wallet without funding it, you can create a new `Wallet` instance. Keep in mind that you need to send XRP to the wallet for it to be a valid account on the ledger.
140+
If you want to generate a wallet without funding it, you can create a new [`Wallet`](https://js.xrpl.org/classes/Wallet.html) instance. Keep in mind that you need to send XRP to the wallet for it to be a valid account on the ledger.
140141
{% /step %}
141142

142143
{% step id="get-account-create-wallet-c-tag" %}
143144
#### (Optional) Use Your Own Wallet Seed
144145

145-
To use an existing wallet seed encoded in [base58][], you can create a `Wallet` instance from it.
146+
To use an existing wallet seed encoded in [base58][], you can create a [`Wallet`](https://js.xrpl.org/classes/Wallet.html) instance from it.
146147
{% /step %}
147148

149+
{% step id="query-xrpl-tag" %}
148150
### 4. Query the XRP Ledger
149151

150-
{% step id="query-xrpl-tag" %}
151-
Use the Client's `request()` method to access the XRP Ledger's [WebSocket API](../../../references/http-websocket-apis/api-conventions/request-formatting.md).
152+
Use the Client's [`request()`](https://js.xrpl.org/classes/Client.html#request) method to access the XRP Ledger's [WebSocket API](../../../references/http-websocket-apis/api-conventions/request-formatting.md).
152153
{% /step %}
153154

155+
{% step id="listen-for-events-tag" %}
154156
### 5. Listen for Events
155157

156-
{% step id="listen-for-events-tag" %}
157-
You can set up handlers for various types of events in `xrpl.js`, such as whenever the XRP Ledger's [consensus process](../../../concepts/consensus-protocol/index.md) produces a new [ledger version](../../../concepts/ledgers/index.md). To do that, first call the [subscribe method][] to get the type of events you want, then attach an event handler using the `on(eventType, callback)` method of the client.
158+
You can set up handlers for various types of events in `xrpl.js`, such as whenever the XRP Ledger's [consensus process](../../../concepts/consensus-protocol/index.md) produces a new [ledger version](../../../concepts/ledgers/index.md). To do that, first call the [subscribe method][] to get the type of events you want, then attach an event handler using the [`on(eventType, callback)`](https://js.xrpl.org/classes/Client.html#on) method of the client.
158159
{% /step %}
159160
161+
{% step id="disconnect-node-tag" when={ "environment": "Node" } %}
160162
### 6. Disconnect
161163
162-
{% step id="disconnect-node-tag" when={ "environment": "Node" } %}
163-
Disconnect when done so Node.js can end the process. The example code waits 10 seconds before disconnecting to allow time for the ledger event listener to receive and display events.
164+
Call the [`disconnect()`](https://js.xrpl.org/classes/Client.html#disconnect) function so Node.js can end the process. The example code waits 10 seconds before disconnecting to allow time for the ledger event listener to receive and display events.
164165
{% /step %}
165166
166167
{% step id="disconnect-web-tag" when={ "environment": "Web" } %}
167-
Disconnect from the ledger when done. The example code waits 10 seconds before disconnecting to allow time for the ledger event listener to receive and display events.
168+
### 6. Disconnect
169+
170+
Call the [`disconnect()`](https://js.xrpl.org/classes/Client.html#disconnect) function to disconnect from the ledger when done. The example code waits 10 seconds before disconnecting to allow time for the ledger event listener to receive and display events.
168171
{% /step %}
169172
173+
{% step id="run-app-node-tag" when={ "environment": "Node" } %}
170174
### 7. Run the Application
171175
172-
{% step id="run-app-node-tag" when={ "environment": "Node" } %}
173176
Finally, in your terminal, run the application like so:
174177
175178
```sh
@@ -237,6 +240,8 @@ Disconnected
237240
{% /step %}
238241
239242
{% step id="run-app-web-tag" when={ "environment": "Web" } %}
243+
### 7. Run the Application
244+
240245
Open the `index.html` file in a web browser.
241246
242247
You should see output similar to the following:

0 commit comments

Comments
 (0)