Skip to content

Commit aa74ce3

Browse files
committed
Add Get Started Walkthrough for Python
1 parent 7cb5f9a commit aa74ce3

File tree

4 files changed

+235
-129
lines changed

4 files changed

+235
-129
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 JavaScript Library](http://xrpl.org/docs/tutorials/javascript/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+
Connected to Testnet
22+
23+
Creating a new wallet and funding it with Testnet XRP...
24+
Attempting to fund address rLq4G7esPJ4ma7iBsXCtTLx4d8fcsQkHd
25+
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
33+
34+
Getting account info...
35+
Response Status: ResponseStatus.SUCCESS
36+
{
37+
"account_data": {
38+
"Account": "rLq4G7esPJ4ma7iBsXCtTLx4d8fcsQkHd",
39+
"Balance": "10000000",
40+
"Flags": 0,
41+
"LedgerEntryType": "AccountRoot",
42+
"OwnerCount": 0,
43+
"PreviousTxnID": "24825D7C3CA2541899928CD4D5489151BF8ABD848E3F4F08186369E5FF7335B2",
44+
"PreviousTxnLgrSeq": 10569458,
45+
"Sequence": 10569458,
46+
"index": "24C7EB6F9A736270ED5A0A8FD12D01C91DF41E7A7D385E2A19A3D263CE0EF208"
47+
},
48+
"account_flags": {
49+
"allowTrustLineClawback": false,
50+
"defaultRipple": false,
51+
"depositAuth": false,
52+
"disableMasterKey": false,
53+
"disallowIncomingCheck": false,
54+
"disallowIncomingNFTokenOffer": false,
55+
"disallowIncomingPayChan": false,
56+
"disallowIncomingTrustline": false,
57+
"disallowIncomingXRP": false,
58+
"globalFreeze": false,
59+
"noFreeze": false,
60+
"passwordSpent": false,
61+
"requireAuthorization": false,
62+
"requireDestinationTag": false
63+
},
64+
"ledger_hash": "BC2570097583BAAC1DD2DFA107B06291DF579CD46248E10C27377FB3F4317A7D",
65+
"ledger_index": 10569458,
66+
"validated": true
67+
}
68+
```
Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,54 @@
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+
print("Connected to Testnet")
12+
# @chunk-end
513

614

7-
# Create a wallet using the testnet faucet:
15+
# @chunk {"steps": ["get-account-create-wallet-tag"]}
16+
# Create a wallet using the Testnet faucet:
817
# https://xrpl.org/xrp-testnet-faucet.html
9-
from xrpl.wallet import generate_faucet_wallet
18+
print("\nCreating a new wallet and funding it with Testnet XRP...")
1019
test_wallet = generate_faucet_wallet(client, debug=True)
20+
test_account = test_wallet.classic_address
21+
print(f"Wallet: {test_account}")
22+
print(f"Account Testnet Explorer URL: ")
23+
print(f" https://testnet.xrpl.org/accounts/{test_account}")
24+
# @chunk-end
1125

12-
# Create an account str from the wallet
13-
test_account = test_wallet.address
1426

27+
# @chunk {"steps": ["get-account-x-address-tag"]}
1528
# Derive an x-address from the classic address:
1629
# 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)
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
2139

2240

41+
# @chunk {"steps": ["query-xrpl-tag"]}
2342
# Look up info about your account
24-
from xrpl.models.requests.account_info import AccountInfo
43+
print("\nGetting account info...")
2544
acct_info = AccountInfo(
2645
account=test_account,
2746
ledger_index="validated",
2847
strict=True,
2948
)
49+
3050
response = client.request(acct_info)
3151
result = response.result
32-
print("response.status: ", response.status)
33-
import json
52+
print("Response Status: ", response.status)
3453
print(json.dumps(response.result, indent=4, sort_keys=True))
54+
# @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)