From e82efa394cdafcf5b05d36262f4044327c496fb5 Mon Sep 17 00:00:00 2001 From: Wo Jake <87929946+wojake@users.noreply.github.com> Date: Sat, 3 Sep 2022 09:59:43 +0000 Subject: [PATCH 1/8] Add python code sample for Submit and Verify Submit a transaction and verify its validity on the ledger using xrpl-py --- .../submit-and-verify/py/submit-and-verify.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 content/_code-samples/submit-and-verify/py/submit-and-verify.py diff --git a/content/_code-samples/submit-and-verify/py/submit-and-verify.py b/content/_code-samples/submit-and-verify/py/submit-and-verify.py new file mode 100644 index 0000000000..a3fbd6e50a --- /dev/null +++ b/content/_code-samples/submit-and-verify/py/submit-and-verify.py @@ -0,0 +1,31 @@ +from xrpl.clients import JsonRpcClient +from xrpl.models.transactions import AccountSet +from xrpl.transaction import safe_sign_and_submit_transaction +from xrpl.core import keypairs +from xrpl.wallet import Wallet + +myAddr = "rfaNymVS1fEREj4FpNroXVEcVVMph6k2Mt" +mySeed = "ss3GZzmyEBxvwB3LUv-----------" + +# Derive and initialize wallet +public, private = keypairs.derive_keypair(mySeed) +wallet_from_seed = Wallet(mySeed, 0) + +# Connect to a testnet node +JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/" +client = JsonRpcClient(JSON_RPC_URL) + +# Construct AccountSet transaction +tx = AccountSet( + account=myAddr, + fee="10", + set_flag=1 # Numerical Value: 1 = asfRequireDest +) + +# Sign the transaction locally & submit transaction and verify its validity on the ledger +my_tx_payment_signed = safe_sign_and_submit_transaction(transaction=tx, wallet=wallet_from_seed, client=client) + +if my_tx_payment_signed.is_successful(): + print("Transaction successful!") +else: + print("Transaction failed") From 88350f05502131e800207c73a01fb0d91dcac619 Mon Sep 17 00:00:00 2001 From: Wo Jake <87929946+wojake@users.noreply.github.com> Date: Sat, 3 Sep 2022 13:21:57 +0000 Subject: [PATCH 2/8] Optimize result's output --- .../submit-and-verify/py/submit-and-verify.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/content/_code-samples/submit-and-verify/py/submit-and-verify.py b/content/_code-samples/submit-and-verify/py/submit-and-verify.py index a3fbd6e50a..643adea7ea 100644 --- a/content/_code-samples/submit-and-verify/py/submit-and-verify.py +++ b/content/_code-samples/submit-and-verify/py/submit-and-verify.py @@ -24,8 +24,15 @@ tx = AccountSet( # Sign the transaction locally & submit transaction and verify its validity on the ledger my_tx_payment_signed = safe_sign_and_submit_transaction(transaction=tx, wallet=wallet_from_seed, client=client) +my_tx_payment_signed = my_tx_payment_signed.result -if my_tx_payment_signed.is_successful(): +result = my_tx_payment_signed["engine_result"] + +if result == "tesSUCCESS": print("Transaction successful!") +elif result == "tefMAX_LEDGER": + print("Transaction failed to achieve consensus") +elif result == "unknown": + print("Transaction status unknown") else: - print("Transaction failed") + print(f"Transaction failed with code {result}") From 1db0295b571f29dba7dc9e3fd2aa8dc15a286fc4 Mon Sep 17 00:00:00 2001 From: Wo Jake <87929946+wojake@users.noreply.github.com> Date: Sun, 4 Sep 2022 16:09:17 +0000 Subject: [PATCH 3/8] Remove `fee` parameter Co-authored-by: LimpidCrypto <97235361+LimpidCrypto@users.noreply.github.com> --- content/_code-samples/submit-and-verify/py/submit-and-verify.py | 1 - 1 file changed, 1 deletion(-) diff --git a/content/_code-samples/submit-and-verify/py/submit-and-verify.py b/content/_code-samples/submit-and-verify/py/submit-and-verify.py index 643adea7ea..58b130ec93 100644 --- a/content/_code-samples/submit-and-verify/py/submit-and-verify.py +++ b/content/_code-samples/submit-and-verify/py/submit-and-verify.py @@ -18,7 +18,6 @@ client = JsonRpcClient(JSON_RPC_URL) # Construct AccountSet transaction tx = AccountSet( account=myAddr, - fee="10", set_flag=1 # Numerical Value: 1 = asfRequireDest ) From 9d2d7ffdf0a12676fb405a4841e0caf3ca51adc2 Mon Sep 17 00:00:00 2001 From: Wo Jake <87929946+wojake@users.noreply.github.com> Date: Sun, 4 Sep 2022 16:11:19 +0000 Subject: [PATCH 4/8] Remove `flag` parameter (redundant) Co-authored-by: LimpidCrypto <97235361+LimpidCrypto@users.noreply.github.com> --- content/_code-samples/submit-and-verify/py/submit-and-verify.py | 1 - 1 file changed, 1 deletion(-) diff --git a/content/_code-samples/submit-and-verify/py/submit-and-verify.py b/content/_code-samples/submit-and-verify/py/submit-and-verify.py index 58b130ec93..4016cec4cd 100644 --- a/content/_code-samples/submit-and-verify/py/submit-and-verify.py +++ b/content/_code-samples/submit-and-verify/py/submit-and-verify.py @@ -18,7 +18,6 @@ client = JsonRpcClient(JSON_RPC_URL) # Construct AccountSet transaction tx = AccountSet( account=myAddr, - set_flag=1 # Numerical Value: 1 = asfRequireDest ) # Sign the transaction locally & submit transaction and verify its validity on the ledger From befb872e3b97c50760d390cf45d320ca24659288 Mon Sep 17 00:00:00 2001 From: Wo Jake <87929946+wojake@users.noreply.github.com> Date: Sun, 4 Sep 2022 16:13:33 +0000 Subject: [PATCH 5/8] usage of `send_reliable_submission` Co-authored-by: LimpidCrypto <97235361+LimpidCrypto@users.noreply.github.com> --- .../_code-samples/submit-and-verify/py/submit-and-verify.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/_code-samples/submit-and-verify/py/submit-and-verify.py b/content/_code-samples/submit-and-verify/py/submit-and-verify.py index 4016cec4cd..4279e85ca3 100644 --- a/content/_code-samples/submit-and-verify/py/submit-and-verify.py +++ b/content/_code-samples/submit-and-verify/py/submit-and-verify.py @@ -21,7 +21,9 @@ tx = AccountSet( ) # Sign the transaction locally & submit transaction and verify its validity on the ledger -my_tx_payment_signed = safe_sign_and_submit_transaction(transaction=tx, wallet=wallet_from_seed, client=client) +my_tx_payment_signed = safe_sign_transaction(transaction=tx, wallet=wallet_from_seed) +response = send_reliable_submission(transaction=my_tx_payment_signed, client=client) +result = response.result["engine_result"] my_tx_payment_signed = my_tx_payment_signed.result result = my_tx_payment_signed["engine_result"] From b581f537288f210b693ad438403804a0aa7b10be Mon Sep 17 00:00:00 2001 From: Wo Jake <87929946+wojake@users.noreply.github.com> Date: Sun, 4 Sep 2022 17:13:39 +0000 Subject: [PATCH 6/8] Fixup --- .../submit-and-verify/py/submit-and-verify.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/content/_code-samples/submit-and-verify/py/submit-and-verify.py b/content/_code-samples/submit-and-verify/py/submit-and-verify.py index 4279e85ca3..881c6624a3 100644 --- a/content/_code-samples/submit-and-verify/py/submit-and-verify.py +++ b/content/_code-samples/submit-and-verify/py/submit-and-verify.py @@ -1,11 +1,13 @@ from xrpl.clients import JsonRpcClient from xrpl.models.transactions import AccountSet -from xrpl.transaction import safe_sign_and_submit_transaction -from xrpl.core import keypairs +from xrpl.transaction import safe_sign_transaction, send_reliable_submission +from xrpl.account import get_next_valid_seq_number +from xrpl.ledger import get_latest_validated_ledger_sequence from xrpl.wallet import Wallet +from xrpl.core import keypairs -myAddr = "rfaNymVS1fEREj4FpNroXVEcVVMph6k2Mt" -mySeed = "ss3GZzmyEBxvwB3LUv-----------" +myAddr = "r31FLxNkfFJwRXbJw82RYB6Fa7jmfA3ix1" +mySeed = "sn51LT5QeaPYhjM1HL9-----------" # Derive and initialize wallet public, private = keypairs.derive_keypair(mySeed) @@ -18,15 +20,15 @@ client = JsonRpcClient(JSON_RPC_URL) # Construct AccountSet transaction tx = AccountSet( account=myAddr, + fee="10", + sequence=get_next_valid_seq_number(address=myAddr, client=client), + last_ledger_sequence=get_latest_validated_ledger_sequence(client=client)+20, ) # Sign the transaction locally & submit transaction and verify its validity on the ledger my_tx_payment_signed = safe_sign_transaction(transaction=tx, wallet=wallet_from_seed) response = send_reliable_submission(transaction=my_tx_payment_signed, client=client) -result = response.result["engine_result"] -my_tx_payment_signed = my_tx_payment_signed.result - -result = my_tx_payment_signed["engine_result"] +result = response.result["meta"]["TransactionResult"] if result == "tesSUCCESS": print("Transaction successful!") From c43c5445d4374df20e342d1aafab4406bc0d3bd2 Mon Sep 17 00:00:00 2001 From: Wo Jake <87929946+wojake@users.noreply.github.com> Date: Mon, 5 Sep 2022 07:50:27 +0000 Subject: [PATCH 7/8] Fixup --- .../submit-and-verify/py/submit-and-verify.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/content/_code-samples/submit-and-verify/py/submit-and-verify.py b/content/_code-samples/submit-and-verify/py/submit-and-verify.py index 881c6624a3..4d8256b8bd 100644 --- a/content/_code-samples/submit-and-verify/py/submit-and-verify.py +++ b/content/_code-samples/submit-and-verify/py/submit-and-verify.py @@ -1,16 +1,12 @@ from xrpl.clients import JsonRpcClient from xrpl.models.transactions import AccountSet -from xrpl.transaction import safe_sign_transaction, send_reliable_submission -from xrpl.account import get_next_valid_seq_number -from xrpl.ledger import get_latest_validated_ledger_sequence +from xrpl.transaction import safe_sign_and_autofill_transaction, send_reliable_submission from xrpl.wallet import Wallet -from xrpl.core import keypairs -myAddr = "r31FLxNkfFJwRXbJw82RYB6Fa7jmfA3ix1" -mySeed = "sn51LT5QeaPYhjM1HL9-----------" +myAddr = "rM4vA4uRpc2MtCoc4vdhhTwWqsWcncwaLL" +mySeed = "ssJ4QYQLXomJLSKBT----------" # Derive and initialize wallet -public, private = keypairs.derive_keypair(mySeed) wallet_from_seed = Wallet(mySeed, 0) # Connect to a testnet node @@ -19,14 +15,12 @@ client = JsonRpcClient(JSON_RPC_URL) # Construct AccountSet transaction tx = AccountSet( - account=myAddr, - fee="10", - sequence=get_next_valid_seq_number(address=myAddr, client=client), - last_ledger_sequence=get_latest_validated_ledger_sequence(client=client)+20, + account=myAddr ) -# Sign the transaction locally & submit transaction and verify its validity on the ledger -my_tx_payment_signed = safe_sign_transaction(transaction=tx, wallet=wallet_from_seed) +# Sign the transaction locally +my_tx_payment_signed = safe_sign_and_autofill_transaction(transaction=tx, wallet=wallet_from_seed, client=client) +# Submit transaction and verify its validity on the ledger response = send_reliable_submission(transaction=my_tx_payment_signed, client=client) result = response.result["meta"]["TransactionResult"] From d07ea444ee513816c4f8cc31a829f30418ae5cc2 Mon Sep 17 00:00:00 2001 From: Wo Jake <87929946+wojake@users.noreply.github.com> Date: Wed, 7 Sep 2022 02:36:43 +0000 Subject: [PATCH 8/8] Use `generate_faucet_wallet` --- .../submit-and-verify/py/submit-and-verify.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/content/_code-samples/submit-and-verify/py/submit-and-verify.py b/content/_code-samples/submit-and-verify/py/submit-and-verify.py index 4d8256b8bd..f94cc74bca 100644 --- a/content/_code-samples/submit-and-verify/py/submit-and-verify.py +++ b/content/_code-samples/submit-and-verify/py/submit-and-verify.py @@ -1,29 +1,28 @@ from xrpl.clients import JsonRpcClient from xrpl.models.transactions import AccountSet from xrpl.transaction import safe_sign_and_autofill_transaction, send_reliable_submission -from xrpl.wallet import Wallet - -myAddr = "rM4vA4uRpc2MtCoc4vdhhTwWqsWcncwaLL" -mySeed = "ssJ4QYQLXomJLSKBT----------" - -# Derive and initialize wallet -wallet_from_seed = Wallet(mySeed, 0) +from xrpl.wallet import Wallet, generate_faucet_wallet # Connect to a testnet node JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/" client = JsonRpcClient(JSON_RPC_URL) +# Generate a wallet and request faucet +test_wallet = generate_faucet_wallet(client=client) +myAddr = test_wallet.classic_address + # Construct AccountSet transaction tx = AccountSet( account=myAddr ) # Sign the transaction locally -my_tx_payment_signed = safe_sign_and_autofill_transaction(transaction=tx, wallet=wallet_from_seed, client=client) +my_tx_payment_signed = safe_sign_and_autofill_transaction(transaction=tx, wallet=test_wallet, client=client) # Submit transaction and verify its validity on the ledger response = send_reliable_submission(transaction=my_tx_payment_signed, client=client) result = response.result["meta"]["TransactionResult"] +print(f"Account: {myAddr}") if result == "tesSUCCESS": print("Transaction successful!") elif result == "tefMAX_LEDGER":