So I have a basic script that attempts to transfer everything from 1 address to another. In order to correctly conserve and to spend the minimum fee, I just build a transaction that uses 100% of the lovelace and let the build command tell me how much I am short, then rebuild the transaction - the fee from the error before.
But that stopped working for some reason. In my current example, the build command says I am short by 168185, then I rebuild minus that fee, and it works fine. I sign, and go to submit and I get this strange error showing my being just a tiny bit short:
Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (FeeTooSmallUTxO (Coin 169593) (Coin 168185))))])
My question, is there a way to know the min fee without going through multiple iterations? and why is this fee different then the one from the build command?
EDIT: I can't actually submit this transaction at all, because when I try to change it to "169593" then the change output of 1408 doesn't meet the minimum utxo threshold for the change output. how can these two be calculated differently? Do I need to build raw and specify the fee explicitly of the higher amount?
Command failed: transaction build Error: The transaction does balance in its use of ada, however the net balance does not meet the minimum UTxO threshold.
Balance: Lovelace 1408
Offending output (change output): addraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + 1408 lovelace
face address of course