Bitcoinj Connect P2SH transaction to withdrawal transaction

I created a P2SH address and sent coins to

Next, I want to send coins from the address 2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r.

How to prepare a P2SH transaction and connect it to the script output?

public static void sendFromP2SH(WalletAppKit kit, Address destAdd, Coin coin) throws AddressFormatException, InsufficientMoneyException, ExecutionException, InterruptedException {
    Transaction tx = new Transaction(TestNet3Params.get());
    tx.addOutput(coin, destAdd); //prepare destination output

    Wallet.SendRequest req = Wallet.SendRequest.forTx(tx);

    //TODO prepare P2SH input for output //
    Script script = P2SHScript(kit); //2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
    TransactionOutput t = null;//... HOW TO CONNECT P2SH input transaction to the output ?


    prepare script for the P2SH address  2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
       public static Script P2SHScript(WalletAppKit kit) {
            ECKey pubClientKey = kit.wallet().getImportedKeys().get(0);
            ECKey pubServerKey = kit.wallet().getImportedKeys().get(1);
            return ScriptBuilder.createP2SHOutputScript(1, ImmutableList.of(pubClientKey, pubServerKey));




source to share

1 answer

How about the next constructor?

public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, Address to)


Inside the code, it computes on the 'to' address to check if it is a multisession and creates the script exit accordingly.



All Articles