Categories
Bitcoin Cryptocurrency Mastering Development

Fail to sign the Segwit Transaction’s input in bitcoinj

I want to spend from a segwit address and it has a P2WPH script, I created this transaction just like creating a normal P2PKH transaction, but just changed the address of the input to the segwit address, I don’t know if this is correct, and signing this transaction in the following method, but it says […]

Categories
Bitcoin Cryptocurrency Mastering Development

How to sign a 2-of-2 multisig address?

I want to implement 2-of-2 multisig in bitcoinj, and I implement the methods which are used to sign the first time and the second time. But there is a bug that using the same key for the first signing and second signing can also pass the transaction verification and can be broadcast. Where the mistake […]

Categories
Bitcoin Cryptocurrency Development

I would like to create a raw transaction with one input and two output, but when I try to broadcast it in testnet, it says validation falied

I implemented it in bitcoinj, and create the raw transaction’s input and output by this method: private static Transaction createFundingTransaction(){ Transaction tx = new Transaction(params); \\add the input ScriptBuilder scriptBuilder = new ScriptBuilder(); scriptBuilder.data(new String(“76a914f21489e6617eb2607f476e6db7f8986f840be52e88ac”).getBytes()); System.out.println(“write your prev UTXO hash in base16, once output from this will input for channel’s creation’s transaction: “); String PrevTxHash_str […]

Categories
Bitcoin Cryptocurrency Development

When creating a Bitcoin raw transaction, the input is connected in bitcoinj

I would like to create a Bitcoin raw transaction and test it on testnet, but after adding the ouput and the input like this: Transaction tx = new Transaction(params); Address target = Address.fromString(params,targetAd); Address source = Address.fromString(params,sourceADDRESS); tx.addOutput(Coin.valueOf(10000),target); long index = 1; String txid = “d2340514953262fdf5ce11f5e6c95c4d3cc5b614f0446d697f7471ae7b5e4a96”; Script script = ScriptBuilder.createOutputScript(source); Sha256Hash txhash = Sha256Hash.wrap(txid); TransactionOutPoint […]

Categories
Bitcoin Cryptocurrency Development

spend from p2sh with bitcoinj

i am try to spend the coins on a p2sh first, i generate p2sh and send coins to that p2sh ECKey clientKey = new ECKey(); ECKey serverKey = new ECKey(); ECKey thirdPartyKey = new ECKey(); List<ECKey> keys = ImmutableList.of(clientKey, serverKey,thirdPartyKey); Script multisigScript = ScriptBuilder.createP2SHOutputScript(2, keys); String address = multisigScript.getToAddress(params).toString(); then i send coins to the […]