mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-19 19:25:51 +00:00
updatee prepare payment section
This commit is contained in:
50
content/_code-samples/xrpl-py/prepare-payment.py
Normal file
50
content/_code-samples/xrpl-py/prepare-payment.py
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
# Define the network client
|
||||
from xrpl.clients import JsonRpcClient
|
||||
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
|
||||
|
||||
# Create a wallet using the testnet faucet:
|
||||
# https://xrpl.org/xrp-testnet-faucet.html
|
||||
from xrpl.wallet import generate_faucet_wallet
|
||||
test_wallet = generate_faucet_wallet(client, debug=True)
|
||||
|
||||
# Create an account str from the wallet
|
||||
test_account = test_wallet.classic_address
|
||||
|
||||
# Derive an x-address from the classic address:
|
||||
# https://xrpaddress.info/
|
||||
from xrpl.core import addresscodec
|
||||
test_xaddress = addresscodec.classic_address_to_xaddress(test_account, tag=12345, is_test_network=True)
|
||||
print("\nClassic address:\n\n", test_account)
|
||||
print("X-address:\n\n", test_xaddress)
|
||||
|
||||
# Prepare payment
|
||||
from xrpl.models.transactions import Payment
|
||||
from xrpl.utils import xrp_to_drops
|
||||
my_tx_payment = Payment(
|
||||
account=test_account,
|
||||
amount=xrp_to_drops(22),
|
||||
destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
sequence=test_wallet.sequence,
|
||||
)
|
||||
|
||||
# print prepared payment
|
||||
print(my_tx_payment)
|
||||
|
||||
# Sign the transaction
|
||||
from xrpl.transaction import safe_sign_and_autofill_transaction
|
||||
|
||||
my_tx_payment_signed = safe_sign_and_autofill_transaction(my_tx_payment,test_wallet, client)
|
||||
|
||||
# Print signed tx
|
||||
print("Signed tx:", my_tx_payment_signed)
|
||||
|
||||
# Submit and send the transaction
|
||||
from xrpl.transaction import send_reliable_submission
|
||||
|
||||
tx_response = send_reliable_submission(my_tx_payment_signed, client)
|
||||
|
||||
# Print tx response
|
||||
print("Tx response:", tx_response)
|
||||
@@ -33,9 +33,7 @@ The `xrpl-py` library supports [Python 3.7](https://www.python.org/downloads/) a
|
||||
|
||||
## Installation
|
||||
|
||||
<!--{# TODO: update link to go directly to package on PyPI when it's available #}-->
|
||||
|
||||
The [`xrpl-py` library](https://github.com/XRPLF/xrpl-py) is available on [PyPI](https://pypi.org/). Install with `pip`:
|
||||
The [`xrpl-py` library](https://github.com/XRPLF/xrpl-py) is available on [PyPI](https://pypi.org/project/xrpl-py/). Install with `pip`:
|
||||
|
||||
|
||||
```py
|
||||
@@ -115,36 +113,23 @@ In this tutorial we only query details about the generated account from the XRP
|
||||
|
||||
To prepare the transaction:
|
||||
|
||||
```py
|
||||
from xrpl.models.transactions import Payment
|
||||
from xrpl.utils import xrp_to_drops
|
||||
{{ include_code("_code-samples/xrpl-py/prepare-payment.py", start_with="# Prepare payment", end_before="# print prepared payment", language="py") }}
|
||||
|
||||
|
||||
my_tx_payment = Payment(
|
||||
account=test_wallet.classic_address,
|
||||
amount=xrp_to_drops(22),
|
||||
destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
sequence=test_wallet.next_sequence_num,
|
||||
)
|
||||
```
|
||||
|
||||
##### Sign
|
||||
|
||||
To sign the transaction:
|
||||
|
||||
```py
|
||||
from xrpl.transaction import send_reliable_submission
|
||||
{{ include_code("_code-samples/xrpl-py/prepare-payment.py", start_with="# Sign the transaction", end_before="# Print signed tx", language="py") }}
|
||||
|
||||
|
||||
my_tx_payment_signed = safe_sign_transaction(my_tx_payment,test_wallet)
|
||||
```
|
||||
##### Send
|
||||
|
||||
To send the transaction:
|
||||
|
||||
```py
|
||||
from xrpl.transaction import send_reliable_submission
|
||||
{{ include_code("_code-samples/xrpl-py/prepare-payment.py", start_with="# Submit and send the transaction", end_before="# Print tx response", language="py") }}
|
||||
|
||||
tx_response = send_reliable_submission(my_tx_payment, test_wallet, client)
|
||||
```
|
||||
|
||||
##### Derive an X-address
|
||||
|
||||
|
||||
Reference in New Issue
Block a user