Files
xrpl-dev-portal/content/_code-samples/escrow/py/create_escrow.py
2022-09-06 20:58:39 -07:00

47 lines
1.6 KiB
Python

from xrpl.wallet import Wallet, generate_faucet_wallet
from xrpl.utils import xrp_to_drops
from xrpl.transaction import (safe_sign_and_autofill_transaction,
send_reliable_submission)
from xrpl.models import EscrowCreate
# Create Escrow
client = JsonRpcClient("https://s.altnet.rippletest.net:51234") # instanstiate ripple client
amount = 10.000 # amount to escrow
receiver_addr = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe" # Example: send back to Testnet Faucet
claim_date = int # date when and after ecsrow can be claimed `xrpl.utils.datetime_to_ripple_time()`
expiry_date = int # date when and after escrow expires `xrpl.utils.datetime_to_ripple_time()`
# optional field
condition = str # cryptic condition that must be met before escrow can be completed | see....
# generate sender wallet with seed
sender_wallet = generate_faucet_wallet(client=client)
# build escrow create transaction
create_txn = EscrowCreate(
account=sender_wallet.classic_address,
amount=xrp_to_drops(amount),
destination=receiver_addr,
finish_after=claim_date,
cancel_after=expiry_date,
condition=condition)
# sign transaction with sender wallet
stxn = safe_sign_and_autofill_transaction(create_txn, sender_wallet, client)
# send signed transaction and wait
stxn_response = send_reliable_submission(stxn, client)
# return result of transaction
stxn_result = stxn_response.result
# parse result and print out the trnasaction result and transaction hash
print(stxn_result["meta"]["TransactionResult"])
print(stxn_result["hash"])