how to get the sender's address in bitcoinj I'm trying to modify the simple wallettemplate to get the sender's address in the transaction list. However since TransactionInput.getFromAddress() doesn't exist now and getConnectedOutput().getAddressFromP2PKHScript() is deprecated, I don't know which is the right way to do so.
Bitcoin transactions don't have a sender's address.

What you're doing is inferring what address previously controlled some or all of the funds involved in the transaction. But:


Previously controlling the funds doesn't mean you found the sender. In case the coins were held by a custodial exchange, the address will be the exchange, and not the sender of the funds. In particular, sending coins back there won't make them reach the right person.
Transactions can be jointly constructed using multiple participants. You can only guess which is which.
The script that previously controlled the funds may not have an associates address at all.


If you want to know what the sender's address of a transaction is, ask the person who sent it (for example if you need a refund address, ask it before showing an address to pay to). If it's not a transaction you're involved in, it's probably none of your business.