6

Due to complete lack of documentation on the subject, how would the pseucode for creating a transaction look using the following functions: createrawtransaction signrawtransaction and sendrawtransaction.

I receive the user transaction for incoming coins on IncomingTxID, when I create a raw transction I want to include at least some of those coins so if they won't confirm, neither will his payout.

cdecker
  • 9,319
  • 1
  • 38
  • 61
  • Related: [C# API for Bitcoin](http://bitcoin.stackexchange.com/q/5461/1878) – makerofthings7 Nov 26 '12 at 17:37
  • How to do this is documented in [_Mastering Bitcoin_ (1st ed.), §"Using Bitcoin Core’s JSON-RPC API from the Command Line"](http://chimera.labs.oreilly.com/books/1234000001802/ch03.html#_using_bitcoin_core_8217_s_json_rpc_api_from_the_command_line), §§"Creating, Signing, and Submitting Transactions Based on Unspent Outputs". – Geremia Nov 28 '17 at 19:53

2 Answers2

3

I am assuming you want to accomplish something akin to what SatoshiDice does. Here is how it can be done, using API calls with the Bitcoin-Qt/bitcoind client:

  1. listunspent - you get the list of all unspent transactions

  2. You determine which ones you want to spend

  3. You use createrawtransaction to create your inputs / outputs, taking txid and vout from the list of transactions that you have that are playing, as well as a list of transactions that constitute a "money supply" for you.

  4. Use signrawtransaction to sign the created transaction

  5. Use sendrawtransaction to send the signed transaction

That should be pretty much it. I have implemented some of that code myself and it is pretty easy once you get a hang of it all.

Stephen Gornick
  • 26,990
  • 12
  • 67
  • 141
ThePiachu
  • 42,931
  • 25
  • 138
  • 347
2

A good way to see this (and also a non-automated method to do this) is available through BrainWallet:

Stephen Gornick
  • 26,990
  • 12
  • 67
  • 141
  • 3
    One bit of caution -- in the raw transaction, any inputs used that are not fully spent go to the miner. So be very careful when composing raw transactions. – Stephen Gornick Mar 18 '13 at 17:50