monero-ecosystem / monero-python

A comprehensive Python module for handling Monero cryptocurrency
BSD 3-Clause "New" or "Revised" License
247 stars 80 forks source link

How is the minimum tx fee set? #98

Closed NikEyX closed 3 years ago

NikEyX commented 3 years ago

Hi,

How is the minimum tx fee set? e.g. if I do a transaction with PRIO_UNIMPORTANT I currently seem to pay 0.00000878 XMR in fees. Where is this set exactly? In the daemon.py code I can see a function that oddly enough seems to get the recent few tx fees from coinbase??? However, I don't think that code is actually being invoked. So how is the minimum tx fee being derived?

emesik commented 3 years ago

AFAIK, fee is a product of transaction size (which depends mostly on the number of inputs and outputs used) and recent history of the network (block sizes I guess). This is a part of the protocol and values aren't free to be decided upon by end users.

PS: Coinbase means the special transaction which pays out block reward to the miner: https://learnmeabitcoin.com/technical/coinbase-transaction

NikEyX commented 3 years ago

Okay, thanks. Would you then know by chance how I can do a transaction that matches exactly a given amount BEFORE fees?

For example if I have an account with 100 XMR and I would like to send an amount to another party that results in EXACTLY 99 XMR on my main account? Right now, using the monero python lib I cannot just send 1 XMR... I would need to send 1 XMR minus fees so that it makes up exactly 1 XMR. However, I cannot do that if I don't know the fees in advance. How can I achieve that?

emesik commented 3 years ago

I guess the only 100% reliable option is to prepare a transaction, check if the amounts match your criteria, adjust, generate another transaction, etc. until you get a right one. Then you submit it to daemon: https://monero-python.readthedocs.io/en/latest/daemon.html#sending-prepared-transactions

This may however fail if your UTxO structure is very unfortunate and the number of inputs changes during the adjustments described above.