DEV Community

darkvallen
darkvallen

Posted on

Sending Payment using Soroban Python SDK

In my previous post, I showed you how to Deploying and Invoking Soroban Smart Contract using Soroban Python SDK. In this post, we'll use Soroban Python SDK to send payment from an account to another account.

Preparation

First, create 2 Futurenet account, one act as the sender, and the other one acts as the receipient. Create accounts at Stellar Laboratory and make sure to fund them.

The accounts that i will be using in this guide:

  • Sender Account :
Public Key: GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN
Secret Key: SD45JGK4S6NCORR6GK66BBRDWNDU322ZT5RQK6RT6D2T7HNFYK3M63DS
Enter fullscreen mode Exit fullscreen mode
  • Receipient Account :
Public Key: GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
Secret Key: SANHLH2IOJMJIHE7XA6VG64GOIQRWDVXD4A77LDW2JAAWHOAZMRVBM3S
Enter fullscreen mode Exit fullscreen mode

Then, the python script that we're going to use is soroban_payment.py from Soroban Python SDK Examples Github Repository. These examples written by overcat, the maintainer of Soroban Python SDK.

Sending Payment

To send a contract, open the soroban_payment.py file and you can adjust the following parameters:

alice_kp = Keypair.from_secret(
    "SD45JGK4S6NCORR6GK66BBRDWNDU322ZT5RQK6RT6D2T7HNFYK3M63DS"
)  # GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN
bob_kp = Keypair.from_secret(
    "SANHLH2IOJMJIHE7XA6VG64GOIQRWDVXD4A77LDW2JAAWHOAZMRVBM3S"
)  # GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
native_token_contract_id = (
    "d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813"
)
Enter fullscreen mode Exit fullscreen mode

alice_kp- Sender Secret Key
bob_kp - Receipient Secret Key
native_token_contract_id - Native token contract id. You can adjust this depends on what asset that you want to send.

    Int128(1000 * 10**7),  # amount, 1000 XLM
Enter fullscreen mode Exit fullscreen mode

You can adjust this line to adjust amount of the asset that you want to send. Note that the amount is in stroops, and a stroop is a 10 millionth of a Lumen.

Quick brief for the changes that i made before :

  • Sender Account : GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN
  • Receipient Account : GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
  • Native Token amount : 1000 XLM (1000.0000000 in stroop)

Save the soroban_payment.py file with your changes.

Before running the script, we will check native token balance of each account using Soroban-CLI .

  • Account 1:
$ soroban contract invoke --id d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813 --secret-key SD45JGK4S6NCORR6GK66BBRDWNDU322ZT5RQK6RT6D2T7HNFYK3M63DS --fn balance -- --id GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN
success
"99999999900"
Enter fullscreen mode Exit fullscreen mode

Account 2:

soroban contract invoke --id d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813 --secret-key SANHLH2IOJMJIHE7XA6VG64GOIQRWDVXD4A77LDW2JAAWHOAZMRVBM3S --fn balance -- --id GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
success
"99999999900"
Enter fullscreen mode Exit fullscreen mode

So both account native token balance now is "99999999900" in stroop.

Then we will send the payment, to send the payment run the script using this command :

python soroban_payment.py
Enter fullscreen mode Exit fullscreen mode

Output :

$ python soroban_payment.py 
simulated transaction: error=None results=[SimulateTransactionResult(auth=['AAAAANk/XHuw68SpyPcnxc68TkEZTTglfh0NkQNWtDv8UogTAAAABHhmZXIAAAADAAAABAAAAAEAAAAIAAAAAAAAAADqc+7BJdwYMVsq0WmKMJi3GBTfSm6PdRVCcCp5dyneHgAAAAQAAAABAAAACAAAAAAAAAAAMq2XtNeKiI/ROw++Ln9vkcDgVeK2sLKvKJiMSAdZxPoAAAAEAAAAAQAAAAUAAAACVAvkAAAAAAAAAAAAAAAAAAAAAAA='], footprint='AAAAAgAAAAbZP1x7sOvEqcj3J8XOvE5BGU04JX4dDZEDVrQ7/FKIEwAAAAMAAAADAAAABtk/XHuw68SpyPcnxc68TkEZTTglfh0NkQNWtDv8UogTAAAABAAAAAEAAAAAAAAAAQAAAAUAAAAITWV0YWRhdGEAAAACAAAAAAAAAAAyrZe014qIj9E7D74uf2+RwOBV4rawsq8omIxIB1nE+gAAAAAAAAAA6nPuwSXcGDFbKtFpijCYtxgU30puj3UVQnAqeXcp3h4=', xdr='AAAAAwAAAAA=')] cost=SimulateTransactionCost(cpu_insns=145027, mem_bytes=7805) latest_ledger=566548
setting footprint and signing transaction...
Signed XDR:
AAAAAgAAAADqc+7BJdwYMVsq0WmKMJi3GBTfSm6PdRVCcCp5dyneHgAAAGQACKKAAAAAAgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAAAAAAAAAFAAAABAAAAAEAAAAGAAAAINk/XHuw68SpyPcnxc68TkEZTTglfh0NkQNWtDv8UogTAAAABQAAAAR4ZmVyAAAABAAAAAEAAAAIAAAAAAAAAADqc+7BJdwYMVsq0WmKMJi3GBTfSm6PdRVCcCp5dyneHgAAAAQAAAABAAAACAAAAAAAAAAAMq2XtNeKiI/ROw++Ln9vkcDgVeK2sLKvKJiMSAdZxPoAAAAEAAAAAQAAAAUAAAACVAvkAAAAAAAAAAAAAAAAAgAAAAbZP1x7sOvEqcj3J8XOvE5BGU04JX4dDZEDVrQ7/FKIEwAAAAMAAAADAAAABtk/XHuw68SpyPcnxc68TkEZTTglfh0NkQNWtDv8UogTAAAABAAAAAEAAAAAAAAAAQAAAAUAAAAITWV0YWRhdGEAAAACAAAAAAAAAAAyrZe014qIj9E7D74uf2+RwOBV4rawsq8omIxIB1nE+gAAAAAAAAAA6nPuwSXcGDFbKtFpijCYtxgU30puj3UVQnAqeXcp3h4AAAABAAAAANk/XHuw68SpyPcnxc68TkEZTTglfh0NkQNWtDv8UogTAAAABHhmZXIAAAADAAAABAAAAAEAAAAIAAAAAAAAAADqc+7BJdwYMVsq0WmKMJi3GBTfSm6PdRVCcCp5dyneHgAAAAQAAAABAAAACAAAAAAAAAAAMq2XtNeKiI/ROw++Ln9vkcDgVeK2sLKvKJiMSAdZxPoAAAAEAAAAAQAAAAUAAAACVAvkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXcp3h4AAABAimiMyJxLhDdPb25fNl+bKfkkI8RD0ychZkUgVgPwheLVkCE6bw71To868CLD4KJr8ebUE1ZNOut03MLZ6jPFAg==
sent transaction: id='57dd82dc6e43c8d7b311520786e36166db0ab4a5527501293ce29d4dd012d1b4' status=<TransactionStatus.PENDING: 'pending'> error=None
waiting for transaction to be confirmed...
waiting for transaction to be confirmed...
waiting for transaction to be confirmed...
transaction status: id='57dd82dc6e43c8d7b311520786e36166db0ab4a5527501293ce29d4dd012d1b4' status=<TransactionStatus.SUCCESS: 'success'> envelope_xdr='AAAAAgAAAADqc+7BJdwYMVsq0WmKMJi3GBTfSm6PdRVCcCp5dyneHgAAAGQACKKAAAAAAgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAAAAAAAAAFAAAABAAAAAEAAAAGAAAAINk/XHuw68SpyPcnxc68TkEZTTglfh0NkQNWtDv8UogTAAAABQAAAAR4ZmVyAAAABAAAAAEAAAAIAAAAAAAAAADqc+7BJdwYMVsq0WmKMJi3GBTfSm6PdRVCcCp5dyneHgAAAAQAAAABAAAACAAAAAAAAAAAMq2XtNeKiI/ROw++Ln9vkcDgVeK2sLKvKJiMSAdZxPoAAAAEAAAAAQAAAAUAAAACVAvkAAAAAAAAAAAAAAAAAgAAAAbZP1x7sOvEqcj3J8XOvE5BGU04JX4dDZEDVrQ7/FKIEwAAAAMAAAADAAAABtk/XHuw68SpyPcnxc68TkEZTTglfh0NkQNWtDv8UogTAAA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10VgYF7dqNoGlLeGkdjW4rEN4y5/XBZ7G5FOWbTC6I0AebcVUsKYFFB6ixX9jAQ6NqpHwVSltsMzhhDHHyug9wgX+sGGnfU5/niQQOWCkHZShBN5TwmwBA==' results=[SCVal(xdr='AAAAAwAAAAA=')] error=None
transaction result: <SCVal [type=3, ic=0]>
Enter fullscreen mode Exit fullscreen mode

From above we can see that transaction is success. Let's check the balance of both account again using the same command before.

  • Sender Account:
$ soroban contract invoke --id d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813 --secret-key SD45JGK4S6NCORR6GK66BBRDWNDU322ZT5RQK6RT6D2T7HNFYK3M63DS --fn balance -- --id GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN

success
"89999999700"
Enter fullscreen mode Exit fullscreen mode
  • Receipient:
$ soroban contract invoke --id d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813 --secret-key SANHLH2IOJMJIHE7XA6VG64GOIQRWDVXD4A77LDW2JAAWHOAZMRVBM3S --fn balance -- --id GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL

success
"109999999800"
Enter fullscreen mode Exit fullscreen mode

From the results above we can see 1000XLM(10000000000 in stroop) from Sender Account has been sent to Receipient Account.

Closing

In this blog post, we have gone over the steps to Send Payment using Soroban Python SDK. You can send your own payments modifying the scripts.

Top comments (0)