Skip to content

Commit

Permalink
transaction example update
Browse files Browse the repository at this point in the history
  • Loading branch information
smartgoo committed Sep 9, 2024
1 parent 00ed57c commit cec700c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions python/examples/transaction_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

async def main():
private_key = PrivateKey("389840d7696e89c38856a066175e8e92697f0cf182b854c883237a50acaf1f69")
source_address = private_key.to_keypair().to_address(network="kaspatest")
print(source_address.to_string())
destination_address = source_address
keypair = private_key.to_keypair()
address = keypair.to_address(network="kaspatest")
print(address.to_string())

client = RpcClient(resolver=Resolver(), network="testnet", network_suffix=10)
await client.connect()
print(f"Client is connected: {client.is_connected}")

utxos = await client.get_utxos_by_addresses({"addresses": [source_address]})
utxos = await client.get_utxos_by_addresses({"addresses": [address]})
utxos = utxos["entries"]

utxos = sorted(utxos, key=lambda x: x['utxoEntry']['amount'], reverse=True)
Expand All @@ -28,13 +28,11 @@ async def main():
fee_rates = await client.get_fee_estimate()
fee = int(fee_rates["estimate"]["priorityBucket"]["feerate"])

total_less_fee = total - fee
utxo1_amt = int(total_less_fee * .1)
utxo2_amt = int(total_less_fee * .9)
output_amount = int(total - fee)

change_address = address
outputs = [
{"address": destination_address, "amount": utxo1_amt},
{"address": destination_address, "amount": utxo2_amt},
{"address": change_address, "amount": output_amount},
]

tx = create_transaction(utxos, outputs, 0, None, 1)
Expand Down

0 comments on commit cec700c

Please sign in to comment.