Skip to content

Commit eb174b8

Browse files
committed
Add review comments
1 parent 9e96d40 commit eb174b8

File tree

3 files changed

+34
-69
lines changed

3 files changed

+34
-69
lines changed

_code-samples/get-started/py/README.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,26 @@ python ./get-acct-info.py
1818
You should see output similar to the following:
1919

2020
```sh
21-
Connected to Testnet
22-
2321
Creating a new wallet and funding it with Testnet XRP...
24-
Attempting to fund address rLq4G7esPJ4ma7iBsXCtTLx4d8fcsQkHd
22+
Attempting to fund address ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
2523
Faucet fund successful.
26-
Wallet: rLq4G7esPJ4ma7iBsXCtTLx4d8fcsQkHd
27-
Account Testnet Explorer URL:
28-
https://testnet.xrpl.org/accounts/rLq4G7esPJ4ma7iBsXCtTLx4d8fcsQkHd
29-
30-
Generating an x-address from the classic address...
31-
Classic address: rLq4G7esPJ4ma7iBsXCtTLx4d8fcsQkHd
32-
X-address: T7QB1hKGbzTLnGWvuXbmQQ6q2AvjnGSBULJE2gNEVWnbGEc
24+
Wallet: ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
25+
Account Testnet Explorer URL:
26+
https://testnet.xrpl.org/accounts/ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
3327

3428
Getting account info...
3529
Response Status: ResponseStatus.SUCCESS
3630
{
3731
"account_data": {
38-
"Account": "rLq4G7esPJ4ma7iBsXCtTLx4d8fcsQkHd",
39-
"Balance": "10000000",
32+
"Account": "ravbHNootpSNQkxyEFCWevSkHsFGDHfyop",
33+
"Balance": "100000000",
4034
"Flags": 0,
4135
"LedgerEntryType": "AccountRoot",
4236
"OwnerCount": 0,
43-
"PreviousTxnID": "24825D7C3CA2541899928CD4D5489151BF8ABD848E3F4F08186369E5FF7335B2",
44-
"PreviousTxnLgrSeq": 10569458,
45-
"Sequence": 10569458,
46-
"index": "24C7EB6F9A736270ED5A0A8FD12D01C91DF41E7A7D385E2A19A3D263CE0EF208"
37+
"PreviousTxnID": "3DACF2438AD39F294C4EFF6132D5D88BCB65D2F2261C7650F40AC1F6A54C83EA",
38+
"PreviousTxnLgrSeq": 12039759,
39+
"Sequence": 12039759,
40+
"index": "148E6F4B8E4C14018D679A2526200C292BDBC5AB77611BC3AE0CB97CD2FB84E5"
4741
},
4842
"account_flags": {
4943
"allowTrustLineClawback": false,
@@ -61,8 +55,8 @@ Response Status: ResponseStatus.SUCCESS
6155
"requireAuthorization": false,
6256
"requireDestinationTag": false
6357
},
64-
"ledger_hash": "BC2570097583BAAC1DD2DFA107B06291DF579CD46248E10C27377FB3F4317A7D",
65-
"ledger_index": 10569458,
58+
"ledger_hash": "CA624D717C4FCDD03BAD8C193F374A77A14F7D2566354A4E9617A8DAD896DE71",
59+
"ledger_index": 12039759,
6660
"validated": true
6761
}
6862
```

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
1010
client = JsonRpcClient(JSON_RPC_URL)
11-
print("Connected to Testnet")
1211
# @chunk-end
1312

1413

@@ -24,20 +23,6 @@
2423
# @chunk-end
2524

2625

27-
# @chunk {"steps": ["get-account-x-address-tag"]}
28-
# Derive an x-address from the classic address:
29-
# https://xrpaddress.info/
30-
print("\nGenerating an x-address from the classic address...")
31-
test_xaddress = addresscodec.classic_address_to_xaddress(
32-
test_account,
33-
tag=12345,
34-
is_test_network=True
35-
)
36-
print(f"Classic address: {test_account}")
37-
print(f"X-address: {test_xaddress}")
38-
# @chunk-end
39-
40-
4126
# @chunk {"steps": ["query-xrpl-tag"]}
4227
# Look up info about your account
4328
print("\nGetting account info...")

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

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ Click **Download** on the top right of the code preview panel to download the so
4747

4848
Follow the steps to create a simple application with `xrpl-py`.
4949

50+
{% step id="import-tag" %}
5051
### 1. Install Dependencies
5152

52-
{% step id="import-tag" %}
5353
Start a new project by creating an empty folder, then move into that folder and set up a Python virtual environment with the necessary dependencies:
5454

5555
```sh
@@ -75,7 +75,11 @@ pip install -r requirements.txt
7575
{% step id="connect-tag" %}
7676
#### Connect to the XRP Ledger Testnet
7777

78-
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `xrpl-py`, use the [`xrp.clients` module](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.clients.html):
78+
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `xrpl-py`, use the [`xrp.clients` module](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.clients.html).
79+
80+
{% admonition type="info" name="Note" %}
81+
The standard approach with `xrpl-py` is to use the JSON-RPC client. While a WebSocket client is available, it requires you to use `async`/`await` throughout your code. For most use cases, stick with JSON-RPC to avoid the complexity of asynchronous programming.
82+
{% /admonition %}
7983

8084
The sample code shows you how to connect to the Testnet, which is one of the available [parallel networks](../../../concepts/networks-and-servers/parallel-networks.md).
8185
{% /step %}
@@ -104,10 +108,8 @@ The sample code in the previous section shows you how to connect to the Testnet,
104108
```
105109
{% /step %}
106110

107-
### 3. Get account
108-
109111
{% step id="get-account-create-wallet-tag" %}
110-
#### Create and Fund a Wallet
112+
### 3. Get account
111113

112114
To store value and execute transactions on the XRP Ledger, you need an account: a [set of keys](../../../concepts/accounts/cryptographic-keys.md#key-components) and an [address](../../../concepts/accounts/addresses.md) that's been [funded with enough XRP](../../../concepts/accounts/index.md#creating-accounts) to meet the [account reserve](../../../concepts/accounts/reserves.md). The address is the identifier of your account and you use the [private key](../../../concepts/accounts/cryptographic-keys.md#private-key) to sign transactions that you submit to the XRP Ledger.
113115

@@ -118,60 +120,46 @@ For testing and development purposes, you can use the [XRP Faucets](/resources/d
118120
To create and fund an account on the Testnet, `xrpl-py` provides the [`generate_faucet_wallet`](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.wallet.html#xrpl.wallet.generate_faucet_wallet) method. This method returns a [`Wallet` instance](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.wallet.html#xrpl.wallet.Wallet).
119121
{% /step %}
120122

121-
{% step id="get-account-x-address-tag" %}
122-
#### Derive an X-Address
123-
124-
You can use `xrpl-py`'s [`xrpl.core.addresscodec`](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.core.addresscodec.html) module to derive an [X-address](https://xrpaddress.info/) from the `Wallet.address` field.
125-
126-
The X-address format [packs the address and destination tag](https://github.com/XRPLF/XRPL-Standards/issues/6) into a more user-friendly value.
127-
{% /step %}
128-
123+
{% step id="query-xrpl-tag" %}
129124
### 4. Query the XRP Ledger
130125

131-
{% step id="query-xrpl-tag" %}
132126
You can query the XRP Ledger to get information about [a specific account](../../../references/http-websocket-apis/public-api-methods/account-methods/index.md), [a specific transaction](../../../references/http-websocket-apis/public-api-methods/transaction-methods/tx.md), the state of a [current or a historical ledger](../../../references/http-websocket-apis/public-api-methods/ledger-methods/index.md), and [the XRP Ledger's decentralized exchange](../../../references/http-websocket-apis/public-api-methods/path-and-order-book-methods/index.md). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](../../../concepts/transactions/reliable-transaction-submission.md).
133127

134-
Here, we use `xrpl-py`'s [`xrpl.account`](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.account.html) module to look up information about the account we got in the previous step.
128+
Use the [account_info method][] to look up information about the account you got in the previous step. Use a request model like `AccountInfo` to validate the request format and catch errors sooner.
135129
{% /step %}
136130

131+
{% step id="run-app-tag" %}
137132
### 5. Run the Application
138133

139-
{% step id="run-app-tag" %}
140134
Finally, in your terminal, run the application like so:
141135

142136
```sh
143-
python3 get-acct-info.py
137+
python get-acct-info.py
144138
```
145139

146140
You should see output similar to this example:
147141

148142
```sh
149-
Connected to Testnet
150-
151143
Creating a new wallet and funding it with Testnet XRP...
152-
Attempting to fund address ranrY8twgDvEGjk8NnC8QsZY1NNyyDV2TZ
144+
Attempting to fund address ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
153145
Faucet fund successful.
154-
Wallet: ranrY8twgDvEGjk8NnC8QsZY1NNyyDV2TZ
146+
Wallet: ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
155147
Account Testnet Explorer URL:
156-
https://testnet.xrpl.org/accounts/ranrY8twgDvEGjk8NnC8QsZY1NNyyDV2TZ
157-
158-
Generating an x-address from the classic address...
159-
Classic address: ranrY8twgDvEGjk8NnC8QsZY1NNyyDV2TZ
160-
X-address: T7CbHsaEVahiEif6dANCuF9WjZNPJi9K3QSnGAfeAyXGEeH
148+
https://testnet.xrpl.org/accounts/ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
161149

162150
Getting account info...
163151
Response Status: ResponseStatus.SUCCESS
164152
{
165153
"account_data": {
166-
"Account": "ranrY8twgDvEGjk8NnC8QsZY1NNyyDV2TZ",
167-
"Balance": "10000000",
154+
"Account": "ravbHNootpSNQkxyEFCWevSkHsFGDHfyop",
155+
"Balance": "100000000",
168156
"Flags": 0,
169157
"LedgerEntryType": "AccountRoot",
170158
"OwnerCount": 0,
171-
"PreviousTxnID": "E509DE6E6DDE8DB14CE22E289B4AE31570040F0A9A8ACE5346B0B7C78C7F55CF",
172-
"PreviousTxnLgrSeq": 10564855,
173-
"Sequence": 10564855,
174-
"index": "C1AC96672DA422C2A68E51DCC158CDF8083898424051B583AC37788FF916CDE3"
159+
"PreviousTxnID": "3DACF2438AD39F294C4EFF6132D5D88BCB65D2F2261C7650F40AC1F6A54C83EA",
160+
"PreviousTxnLgrSeq": 12039759,
161+
"Sequence": 12039759,
162+
"index": "148E6F4B8E4C14018D679A2526200C292BDBC5AB77611BC3AE0CB97CD2FB84E5"
175163
},
176164
"account_flags": {
177165
"allowTrustLineClawback": false,
@@ -189,16 +177,14 @@ Response Status: ResponseStatus.SUCCESS
189177
"requireAuthorization": false,
190178
"requireDestinationTag": false
191179
},
192-
"ledger_hash": "E83D8A31D66ABBFB435BB899B1A21448A2BCE66BB22B47F065EF713A2305820C",
193-
"ledger_index": 10564855,
180+
"ledger_hash": "CA624D717C4FCDD03BAD8C193F374A77A14F7D2566354A4E9617A8DAD896DE71",
181+
"ledger_index": 12039759,
194182
"validated": true
195183
}
196184
```
197185

198186
The response fields that you want to inspect in most cases are:
199187

200-
- `account_data.Sequence` — This is the sequence number of the next valid transaction for the account. You need to specify the sequence number when you prepare transactions. With `xrpl-py`, you can use the [`get_next_valid_seq_number`](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.account.html#xrpl.account.get_next_valid_seq_number) to get this automatically from the XRP Ledger. See an example of this usage in the project [README](https://github.com/XRPLF/xrpl-py#serialize-and-sign-transactions).
201-
202188
- `account_data.Balance` — This is the account's balance of [XRP, in drops][]. You can use this to confirm that you have enough XRP to send (if you're making a payment) and to meet the [current transaction cost](../../../concepts/transactions/transaction-cost.md#current-transaction-cost) for a given transaction.
203189

204190
- `validated` — Indicates whether the returned data is from a [validated ledger](../../../concepts/ledgers/open-closed-validated-ledgers.md). When inspecting transactions, it's important to confirm that [the results are final](../../../concepts/transactions/finality-of-results/index.md) before further processing the transaction. If `validated` is `true` then you know for sure the results won't change. For more information about best practices for transaction processing, see [Reliable Transaction Submission](../../../concepts/transactions/reliable-transaction-submission.md).

0 commit comments

Comments
 (0)