I'm working on a project where BTC comes to address A, then gets sent to address B. I wanna clear out address A, like get it to zero BTC if possible. Just to clarify, not creating any malware here, so chill. Using python with bitcoinlib for this.
Yeah, makes sense. You can pick any of your inputs. Some wallets help with that, but really, you can choose whatever coins and the order doesn't matter. Just keep in mind the final size of the transaction in virtual bytes. You could even prep a zero-fee transaction, check the size, and adjust outputs accordingly.
When mentioning inputs, you should be talking about UTXOs. It’s easier to filter them by address for your case, but you can also sort by amount or how long they’ve been around. If you’re into Python, hooking up a Bitcoin node with Bitcoinlib or using an external API would be smart for handling transactions.
Honestly, trying to figure out the fee manually is tricky without an API. You can't just calculate it out of the blue. Fees depend on the mempool size, but you really need to analyze past transactions to get an idea of what fees are like.