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.

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.

  • 7
    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:49
  • How about fee calculation? – Shamoon Jul 29 '13 at 14:12
  • @Shamoon bitcoinfees.com - you base them on the number of inputs and outputs. – ThePiachu Jul 29 '13 at 15:26
2

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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.