Nami does not implement a function to balance an unbalanced transaction. Therefore, the Nami demo of the Plutus Github repository implements this step (as a temporary workaround) in the function exports.balanceTxImpl = txCbor => ()
that can be found here: https://github.com/input-output-hk/plutus-apps/blob/main/plutus-pab/demo/pab-nami/client/src/Cardano/Wallet/Nami.js
Taking a closer look at this function, one notices that it just fetches some stuff and calls the Nami implementation for building the transaction:
return buildTx({ 'paymentAddr': changeAddrBech32 }, utxos, tx.body().outputs(), pp)
What surprised me was that the inputs of the unbalanced transaction are not passed to buildTx
! How can this work ? It works in the demo because it only implements a simple transaction where A transfers some funds to B. But in a more complicated transaction, there could be some script UTxOs in the inputs of the unbalanced transaction. How are these taken into account ? I have the impression that they are not. Am I missing something ?