Yes, fee = total inputs - total outputs is correct. However, my question is how to calculate transaction fee to make it enough to be broadcasted successfully but not too much? Considering the transaction contains multiple inputs and outputs.
There are a default option min_fee_rate in the ckb.toml: 1000 Shannons/KB. For a typical transfer tx which contains two inputs and two outputs, the tx size is 597 bytes, to calculate tx fee we need plus extra 4 bytes for the serialization consumption; so the min tx fee is (597 + 4) * 1000 / 1000 = 601 shannons. You can send a tx with 601 shannons fee, and try to increase the fee if the tx can’t get committed. https://github.com/nervosnetwork/ckb/blob/develop/resource/ckb.toml#L109
Based on your previous answers, how do you get the result that a transaction contains 2 inputs and 2 outputs would have size of 597 bytes if an input only occupies 16 bytes and an output only 61 bytes?