user27532: I'm using bitcoinJ and I want to verify if some of the destination addresses in a transaction belongs to my wallet when I receive a amount of bitcoin. How can I verify it?

user30396: you could check thepubkey hash in the transaction outputs
this code for exemple check if an adresse belonging to your wallet is in the output
    Address to= null;
        boolean tome= false;
        //from = tx.getInputs().get(0).getFromAddress();
        to=tx.getOutputs().get(0).getScriptPubKey().getToAddress(Constants.NETWORK_PARAMETERS);
tome= w.isPubKeyHashMine(from.getHash160());
        return tome;


27532: <p>I'm using bitcoinJ and I want to verify if some of the destination addresses in a transaction belongs to my wallet when I receive a amount of bitcoin. How can I verify it?</p>
 30396: <p>you could check thepubkey hash in the transaction outputs</p>

<p>this code for exemple check if an adresse belonging to your wallet is in the output</p>

<pre><code>    Address to= null;
        boolean tome= false;
        //from = tx.getInputs().get(0).getFromAddress();
        to=tx.getOutputs().get(0).getScriptPubKey().getToAddress(Constants.NETWORK_PARAMETERS);
tome= w.isPubKeyHashMine(from.getHash160());
        return tome;
</code></pre>
