I am trying to extract the exact amount of BTC deposited and withdrawn from BTC address (from hardware wallets like Trezor, ledger nano, ...). So if the address is pay-to-pubkey-hash then I can easily track amount through its transaction id hash -> outputs BUT when the address is pay-to-script-hash then I am having a hard time recognizing which one is Change and which one is withdrawing amount from Txn Hash detail. Is there any way to distinguish change and withdraw amount for P2SH address.
P2SH: https://api.blockcypher.com/v1/btc/main/txs/87d5fa33ae3f1754bb1618c8559b8451f64de1e396627fad65a19b74b2c72b86 ( difficulty finding)
https://api.blockcypher.com/v1/btc/main/txs/d7cdb1f910ac15d99ee98a28c276ccfccd5fd6592cf01528eb57a871e789b709 ( This is easier as output is withdraw amount)