Skip to content

Commit 01ed305

Browse files
Merge pull request #3299 from XRPLF/python-get-started-code-walkthrough
Add Get Started Walkthrough for Python
2 parents d6b55ab + eb174b8 commit 01ed305

File tree

4 files changed

+214
-143
lines changed

4 files changed

+214
-143
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Get Started Using Python Library
2+
3+
Connects to the XRP Ledger and gets account information using Python.
4+
5+
To download the source code, see [Get Started Using Python Library](http://xrpl.org/docs/tutorials/python/build-apps/get-started).
6+
7+
## Run the Code
8+
9+
Quick setup and usage:
10+
11+
```sh
12+
python -m venv .venv
13+
source .venv/bin/activate
14+
pip install -r requirements.txt
15+
python ./get-acct-info.py
16+
```
17+
18+
You should see output similar to the following:
19+
20+
```sh
21+
Creating a new wallet and funding it with Testnet XRP...
22+
Attempting to fund address ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
23+
Faucet fund successful.
24+
Wallet: ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
25+
Account Testnet Explorer URL:
26+
https://testnet.xrpl.org/accounts/ravbHNootpSNQkxyEFCWevSkHsFGDHfyop
27+
28+
Getting account info...
29+
Response Status: ResponseStatus.SUCCESS
30+
{
31+
"account_data": {
32+
"Account": "ravbHNootpSNQkxyEFCWevSkHsFGDHfyop",
33+
"Balance": "100000000",
34+
"Flags": 0,
35+
"LedgerEntryType": "AccountRoot",
36+
"OwnerCount": 0,
37+
"PreviousTxnID": "3DACF2438AD39F294C4EFF6132D5D88BCB65D2F2261C7650F40AC1F6A54C83EA",
38+
"PreviousTxnLgrSeq": 12039759,
39+
"Sequence": 12039759,
40+
"index": "148E6F4B8E4C14018D679A2526200C292BDBC5AB77611BC3AE0CB97CD2FB84E5"
41+
},
42+
"account_flags": {
43+
"allowTrustLineClawback": false,
44+
"defaultRipple": false,
45+
"depositAuth": false,
46+
"disableMasterKey": false,
47+
"disallowIncomingCheck": false,
48+
"disallowIncomingNFTokenOffer": false,
49+
"disallowIncomingPayChan": false,
50+
"disallowIncomingTrustline": false,
51+
"disallowIncomingXRP": false,
52+
"globalFreeze": false,
53+
"noFreeze": false,
54+
"passwordSpent": false,
55+
"requireAuthorization": false,
56+
"requireDestinationTag": false
57+
},
58+
"ledger_hash": "CA624D717C4FCDD03BAD8C193F374A77A14F7D2566354A4E9617A8DAD896DE71",
59+
"ledger_index": 12039759,
60+
"validated": true
61+
}
62+
```
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1+
# @chunk {"steps": ["connect-tag"]}
12
# Define the network client
23
from xrpl.clients import JsonRpcClient
4+
from xrpl.wallet import generate_faucet_wallet
5+
from xrpl.core import addresscodec
6+
from xrpl.models.requests.account_info import AccountInfo
7+
import json
8+
39
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
410
client = JsonRpcClient(JSON_RPC_URL)
11+
# @chunk-end
512

613

7-
# Create a wallet using the testnet faucet:
14+
# @chunk {"steps": ["get-account-create-wallet-tag"]}
15+
# Create a wallet using the Testnet faucet:
816
# https://xrpl.org/xrp-testnet-faucet.html
9-
from xrpl.wallet import generate_faucet_wallet
17+
print("\nCreating a new wallet and funding it with Testnet XRP...")
1018
test_wallet = generate_faucet_wallet(client, debug=True)
11-
12-
# Create an account str from the wallet
13-
test_account = test_wallet.address
14-
15-
# Derive an x-address from the classic address:
16-
# https://xrpaddress.info/
17-
from xrpl.core import addresscodec
18-
test_xaddress = addresscodec.classic_address_to_xaddress(test_account, tag=12345, is_test_network=True)
19-
print("\nClassic address:\n\n", test_account)
20-
print("X-address:\n\n", test_xaddress)
19+
test_account = test_wallet.classic_address
20+
print(f"Wallet: {test_account}")
21+
print(f"Account Testnet Explorer URL: ")
22+
print(f" https://testnet.xrpl.org/accounts/{test_account}")
23+
# @chunk-end
2124

2225

26+
# @chunk {"steps": ["query-xrpl-tag"]}
2327
# Look up info about your account
24-
from xrpl.models.requests.account_info import AccountInfo
28+
print("\nGetting account info...")
2529
acct_info = AccountInfo(
2630
account=test_account,
2731
ledger_index="validated",
2832
strict=True,
2933
)
34+
3035
response = client.request(acct_info)
3136
result = response.result
32-
print("response.status: ", response.status)
33-
import json
37+
print("Response Status: ", response.status)
3438
print(json.dumps(response.result, indent=4, sort_keys=True))
39+
# @chunk-end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xrpl-py==4.3.0

0 commit comments

Comments
 (0)