user4677: 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

user5122: You should be able to create a transaction draft where you should specify a fee of 200000 lovelace (to have the same transaction size as the final transaction), then estimate the fees, and create the final transaction.
You can also use "cardano-cli transaction build" command and you don't need to calculate the transaction fees or build the transaction 2 times, you only build it once, sign it and submit it.
In case the change is smaller than 1 ADA, the only way to do the transaction without consuming another UTxO is to pay a higher fee for the transaction (add the change to the fee) or to send a higher amount to the destination address than what you wanted to send (add it to the output instead of paying it as a fee).

user2775: If you want to send everything in a wallet the new way that calculates the fee and adds ttl you can query for all the utxo's in the wallet.
cardano-cli query utxo \
--address $(cat payment.addr) \
--mainnet

grab all the utxo's and add them as tx-in as you normally would. You can have multiple in and out.
If it is all going to one place use --change-address. It will send whatevers left over after the fee to that address.
cardano-cli transaction build \
--tx-in a-utxo#1 \
--tx-in another-utxo#0 \
--change-address <to-addr> \
--witness-override 1 \
--out-file tx.unsigned \
--alonzo-era \
--mainnet

It will print the fee. Witness is the number of keys needed for signing. 1 if it's just sending ada somewhere.
cold machine-
cardano-cli transaction sign \
--tx-body-file tx.unsigned \
--signing-key-file payment.skey \
--mainnet \
--out-file tx.signed

-online submit
cardano-cli transaction submit \
--tx-file tx.signed \
--mainnet


4677: <p>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.</p>
<p>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:</p>
<pre><code>Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (FeeTooSmallUTxO (Coin 169593) (Coin 168185))))])
</code></pre>
<p>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?</p>
<p>EDIT:
I can't actually submit this transaction at all, because when I try to change it to &quot;169593&quot; 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?</p>
<pre><code>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
</code></pre>
<p>face address of course</p>
 5122: <p>You should be able to create a transaction draft where you should specify a fee of 200000 lovelace (to have the same transaction size as the final transaction), then estimate the fees, and create the final transaction.</p>
<p>You can also use &quot;cardano-cli transaction build&quot; command and you don't need to calculate the transaction fees or build the transaction 2 times, you only build it once, sign it and submit it.</p>
<p>In case the change is smaller than 1 ADA, the only way to do the transaction without consuming another UTxO is to pay a higher fee for the transaction (add the change to the fee) or to send a higher amount to the destination address than what you wanted to send (add it to the output instead of paying it as a fee).</p>
 2775: <p>If you want to send everything in a wallet the new way that calculates the fee and adds ttl you can query for all the utxo's in the wallet.</p>
<pre><code>cardano-cli query utxo \
--address $(cat payment.addr) \
--mainnet
</code></pre>
<p>grab all the utxo's and add them as tx-in as you normally would. You can have multiple in and out.</p>
<p>If it is all going to one place use --change-address. It will send whatevers left over after the fee to that address.</p>
<pre><code>cardano-cli transaction build \
--tx-in a-utxo#1 \
--tx-in another-utxo#0 \
--change-address &lt;to-addr&gt; \
--witness-override 1 \
--out-file tx.unsigned \
--alonzo-era \
--mainnet
</code></pre>
<p>It will print the fee. Witness is the number of keys needed for signing. 1 if it's just sending ada somewhere.</p>
<p>cold machine-</p>
<pre><code>cardano-cli transaction sign \
--tx-body-file tx.unsigned \
--signing-key-file payment.skey \
--mainnet \
--out-file tx.signed
</code></pre>
<p>-online submit</p>
<pre><code>cardano-cli transaction submit \
--tx-file tx.signed \
--mainnet
</code></pre>
