spend from p2sh with bitcoinj


i’m attempt to spend the cash on a p2sh

first, i generate p2sh and ship cash to that p2sh

ECKey clientKey = new ECKey();
ECKey serverKey = new ECKey();
ECKey thirdPartyKey = new ECKey();
Checklist<ECKey> keys = ImmutableList.of(clientKey, serverKey,thirdPartyKey);
Script multisigScript = ScriptBuilder.createP2SHOutputScript(2, keys);
String handle = multisigScript.getToAddress(params).toString();

then i ship cash to the “handle” on testnet3

second, i take advantage of the pockets in bitcoinj to observe the “handle” and get the tx

WalletAppKit walletAppKit = new WalletAppKit(params, new File("./btcWallet"), "check");
Pockets walletTemp = walletAppKit.pockets();
Handle watchAddress = Handle.fromString(params, "2NGY4n3Wc2iftWufhUg2MzZtccbkQWgdUiz");
 Set<Transaction> transSet = walletTemp.getTransactions(false);

third, after i get the tx and the output, i wish to spend it

TransactionOutput out = ...//output that the second step i get from the tx
Script scriptOut = out.getScriptPubKey()
Coin outValue = Coin.valueOf(10000);
Script redeemScript = ScriptBuilder.createRedeemScript(2, keys);
Handle sendAddress = LegacyAddress.fromBase58(params, "2N6846hvswyZEdJ5DuEcjQZPaT5Xwb6PdGT");
Transaction spendTx = new Transaction(params);
spendTx.addOutput(outValue, sendAddress);
TransactionInput enter = spendTx.addInput(out);

Sha256Hash sighash = spendTx.hashForSignature(0, redeemScript, Transaction.SigHash.ALL,
ECKey.ECDSASignature cSignature = clientKey.signal(sighash);
ECKey.ECDSASignature sSignature = serverKey.signal(sighash);
TransactionSignature cTransactionSignature = new TransactionSignature(cSignature, Transaction.SigHash.ALL,
TransactionSignature sTransactionSignature = new TransactionSignature(sSignature, Transaction.SigHash.ALL,

Script inputScript = ScriptBuilder.createP2SHMultiSigInputScript(ImmutableList.of(cTransactionSignature, sTransactionSignature), scriptOut);

it have error at “enter.confirm(out);”,Script resulted in a non-true stack: [] [3044022043d0cdddb087c4db2937a3b656c37bf240fd95e16714125c0672875bb18b4c1902200f96e1ec0adc2258e324cbacba598cb72d502a4e3185212dea40c50b365d3fb901] []

i don’t kown the place my code is fallacious and remedy it.

discover a comparable downside, however not the identical [1]: Errors when constructing/sending multisig transactions

Supply hyperlink

Leave a reply