Tell me, I have an excellent Python script that creates a transaction for payment with BTC coins, but the commission function is not written or added to the code. Tell me how to add a commission fee? What needs to be changed in the code?
from io import BytesIO
from ecc import *
from tx import *
pk = PrivateKey.parse("Kyyd********privkey********D5LHv")
pk.address()
# constructing an unsigned transaction
# input
prev_tx = bytes.fromhex("9087a21953d35be57b80cc4f8a9e96b8d66e8588ecafb2af8f97b1b71789e0ce")
prev_index = 0
tx_in = TxIn(prev_tx, prev_index, b'', 0xffffffff)
tx_in._script_pubkey = Tx.get_address_data(pk.address())['script_pubkey']
tx_in._value = 500000
tx_ins = [ tx_in ]
# outputs
tx_outs = [
# sending some money to 1ND7BjA2zqqq7Nk3rJDecBbpw6bL3KebbG3
TxOut(100000, Tx.get_address_data("1ND7BjA2zqqq7Nk3rJDecBbpw6bL3KebbG3")['script_pubkey'].serialize()),
# change goes back to the same address
TxOut(390000, Tx.get_address_data(pk.address())['script_pubkey'].serialize())
]
tx = Tx(1, tx_ins, tx_outs, 0, testnet=True)










