Can somebody help me with step-by-step list of how to create a multi signature 2-of-3 transaction using bitcoinj api?
2 Answers
ECKey keyA = <something>
ECKey keyB = <something>
ECKey keyC = <something>
Transaction aTransaction = new Transaction(params);
List<ECKey> keyList = ImmutableList.of(keyA, keyB, keyC);
Script script = ScriptBuilder.createMultiSigOutputScript(2, keyList); //2 of 3 multisig
Coin value = Coin.valueOf(0,10); // 0.1 btc
aTransaction.addOutput(value, script);
Wallet.SendRequest request = Wallet.SendRequest.forTx(aTransaction.addOutput);
wallet.completeTx(request); // fill in coins
See mikes documentation
-
bitcoin.stackexchange.com/questions/3718/… I want to create multisignature Address using private key how can i secure Wallet with that Commented Jun 26, 2015 at 11:24
-
Thanks for the code. Can you please also do it without the wallet contraption?– Jus12Commented Dec 8, 2015 at 8:27
you have an exemple in bitcoinj documentation :
https://bitcoinj.github.io/working-with-contracts
Let’s see how to do it:
// Create a random key.
ECKey clientKey = new ECKey();
// We get the other parties public key from somewhere ...
ECKey serverKey = new ECKey(null, publicKeyBytes);
// Prepare a template for the contract.
Transaction contract = new Transaction(params);
List<ECKey> keys = ImmutableList.of(clientKey, serverKey);
// Create a 2-of-2 multisig output script.
Script script = ScriptBuilder.createMultiSigOutputScript(2, keys);
// Now add an output for 0.50 bitcoins that uses that script.
Coin amount = Coin.valueOf(0, 50);
contract.addOutput(amount, script);
// We have said we want to make 0.5 coins controlled by us and them.
// But it's not a valid tx yet because there are no inputs.
Wallet.SendRequest req = Wallet.SendRequest.forTx(contract);
wallet.completeTx(req); // Could throw InsufficientMoneyException
// Broadcast and wait for it to propagate across the network.
// It should take a few seconds unless something went wrong.
peerGroup.broadcastTransaction(req.tx).get();