在我的previous post中,我向您展示了如何使用Soroban Python SDK部署和调用Soroban Smart合同。在这篇文章中,我们将使用Soroban Python SDK将付款从一个帐户发送到另一个帐户。
准备
首先,创建2个Futurenet帐户,一个作为发件人,另一个作为接收器。在Stellar Laboratory创建帐户,并确保为其提供资金。
我将在本指南中使用的帐户:
- 发送者帐户:
Public Key: GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN
Secret Key: SD45JGK4S6NCORR6GK66BBRDWNDU322ZT5RQK6RT6D2T7HNFYK3M63DS
- 接收帐户:
Public Key: GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
Secret Key: SANHLH2IOJMJIHE7XA6VG64GOIQRWDVXD4A77LDW2JAAWHOAZMRVBM3S
然后,我们要使用的Python脚本是Soroban Python SDK Examples Github Repository的koude0。这些示例由overcat(Soroban Python SDK的维护者)撰写。
发送付款
要发送合同,打开soroban_payment.py
文件,您可以调整以下参数:
alice_kp = Keypair.from_secret(
"SD45JGK4S6NCORR6GK66BBRDWNDU322ZT5RQK6RT6D2T7HNFYK3M63DS"
) # GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN
bob_kp = Keypair.from_secret(
"SANHLH2IOJMJIHE7XA6VG64GOIQRWDVXD4A77LDW2JAAWHOAZMRVBM3S"
) # GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
native_token_contract_id = (
"d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813"
)
alice_kp
-发件人秘密键
bob_kp
-接收器秘密键
native_token_contract_id
-本地令牌合同ID。您可以调整此功能取决于要发送的资产。
Int128(1000 * 10**7), # amount, 1000 XLM
您可以调整此行以调整要发送的资产的数量。请注意,该金额位于stroops
中,而stroop
是腔内的1000万。
快速简介我之前所做的更改:
- 发件人帐户:gdvhh3wbexobqmk3fliwtcrqtc3rqfg7jjxi65ivijycu6lxfhpb4mhn
- 接收帐户:GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
- 本地令牌金额:1000 XLM(
stroop
中的1000.0000000)
使用更改保存soroban_payment.py
文件。
在运行脚本之前,我们将使用Soroban-CLI检查每个帐户的本机代币余额。
- 帐户1:
$ soroban contract invoke --id d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813 --secret-key SD45JGK4S6NCORR6GK66BBRDWNDU322ZT5RQK6RT6D2T7HNFYK3M63DS --fn balance -- --id GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN
success
"99999999900"
帐户2:
soroban contract invoke --id d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813 --secret-key SANHLH2IOJMJIHE7XA6VG64GOIQRWDVXD4A77LDW2JAAWHOAZMRVBM3S --fn balance -- --id GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
所以两个帐户本机代币余额现在都是stroop
中的“ 99999999900”。
然后,我们将发送付款,使用此命令发送付款运行:
python soroban_payment.py
输出:
$ 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/XHuw68SpyPcnxc68TkEZTTglfh0NkQNWtDv8UogTAAAABAAAAAEAAAAAAAAAAQAAAAUAAAAITWV0YWRhdGEAAAACAAAAAAAAAAAyrZe014qIj9E7D74uf2+RwOBV4rawsq8omIxIB1nE+gAAAAAAAAAA6nPuwSXcGDFbKtFpijCYtxgU30puj3UVQnAqeXcp3h4AAAABAAAAANk/XHuw68SpyPcnxc68TkEZTTgl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可以看到交易是成功。让我们在使用同一命令之前再次检查两个帐户的余额。
- 发送者帐户:
$ soroban contract invoke --id d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813 --secret-key SD45JGK4S6NCORR6GK66BBRDWNDU322ZT5RQK6RT6D2T7HNFYK3M63DS --fn balance -- --id GDVHH3WBEXOBQMK3FLIWTCRQTC3RQFG7JJXI65IVIJYCU6LXFHPB4MHN
success
"89999999700"
- 接收器:
$ soroban contract invoke --id d93f5c7bb0ebc4a9c8f727c5cebc4e41194d38257e1d0d910356b43bfc528813 --secret-key SANHLH2IOJMJIHE7XA6VG64GOIQRWDVXD4A77LDW2JAAWHOAZMRVBM3S --fn balance -- --id GAZK3F5U26FIRD6RHMH34LT7N6I4BYCV4K3LBMVPFCMIYSAHLHCPV3EL
success
"109999999800"
从上面的结果我们可以从发送者帐户中看到1000xlm(stroop
中的10000000000)已发送到接收器帐户。
关闭
在这篇博客文章中,我们已经介绍了使用Soroban Python SDK发送付款的步骤。您可以发送自己的付款来修改脚本。