How do I create an offline transaction in java to broadcast via blockchain.info?

5

2

Blockchain.info has a PushTX API.

How do I create & sign a raw transaction in Java for use in this API? Should I use bitcoinj?

Are there any code samples?

ripper234

Posted 2013-02-16T07:11:27.430

Reputation: 25 192

Answers

4

Mike Hearn's WalletTool (included in the bitcoinj library) is a pretty good starting point.

If you have a look at the 'send' method in WalletTool you can see that it:

1) Creates a SendRequest

2) Decrypts the private key if necessary

3) Completes the tx to get the inputs and find the fee

4) Signs the tx

5) Starts up a PeerGroup

6) Broadcasts it

For an offline transaction you can do 1 to 4, serialize the tx and then call the blockchain pushtx.

There is a method on Transaction called bitcoinSerialize to convert it to the bytes that need transmitting. I think you just have to convert the bytes to hex for the blockchain pushtx but you would have to try it out.

jim618

Posted 2013-02-16T07:11:27.430

Reputation: 3 205

5

Check out https://github.com/ValleZ/Paper-Wallet - it is android lite project what does this task. Start with createTransaction method in https://github.com/ValleZ/Paper-Wallet/blob/master/app/src/main/java/ru/valle/btc/BTCUtils.java

user2112961

Posted 2013-02-16T07:11:27.430

Reputation: 163