Manually creating transactions

6

2

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.

user1841964

Posted 2012-11-26T15:57:55.710

Reputation: 61

How to do this is documented in Mastering Bitcoin (1st ed.), §"Using Bitcoin Core’s JSON-RPC API from the Command Line", §§"Creating, Signing, and Submitting Transactions Based on Unspent Outputs".

Geremia 2017-11-28T19:53:19.737

Related: C# API for Bitcoin

goodguys_activate 2012-11-26T17:37:21.227

Answers

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.

ThePiachu

Posted 2012-11-26T15:57:55.710

Reputation: 41 594

7One 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 2013-03-18T17:49:29.737

How about fee calculation?Shamoon 2013-07-29T14:12:45.107

@Shamoon http://bitcoinfees.com/ - you base them on the number of inputs and outputs.

ThePiachu 2013-07-29T15:26:15.600

2

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

Stephen Gornick

Posted 2012-11-26T15:57:55.710

Reputation: 26 118

3One 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 2013-03-18T17:50:41.437