4

Can somebody help me with step-by-step list of how to create a multi signature 2-of-3 transaction using bitcoinj api?

user27079
  • 73
  • 4

2 Answers2

3
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

Jonas Schnelli
  • 6,052
  • 1
  • 21
  • 34
  • http://bitcoin.stackexchange.com/questions/3718/what-are-multi-signature-transactions

    I want to create multisignature Address using private key how can i secure Wallet with that

    – user27079 Jun 26 '15 at 11:24
  • Thanks for the code. Can you please also do it without the wallet contraption? – Jus12 Dec 08 '15 at 08:27
2

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();
Badr Bellaj
  • 1,151
  • 12
  • 18