# Gavin Andresen # 2012-06-14 13:31:38 # https://bitcointalk.org/index.php?topic=87545.msg962287#msg962287 Cross-posting from the bitcoin-development list: @p{par} I submitted a pull request yesterday that implements low-level "raw" transaction, and am looking for feedback on the API and help with trying to test/break it. @p{par} Design doc: @s{(link)} @p{brk} Pull request: @s{(link)} @p{brk} Test plan: @s{(link)} @p{par} Playing around with this API on the command line I'm pretty happy with the level of abstraction and the way it interacts with existing RPC commands; for example, "createrawtx" is just like "sendmany" in the way outputs are specified. @p{par} The signrawtx method is the key new method; it takes a raw transaction, signs as many inputs as it can, and returns the same raw transaction with signatures. Typical usage would be: @p{par} Funds are sitting in a multisignature transaction output, and it is time to gather signatures and spend them. @p{par} Assumption: you know the multisignature transaction's [txid, outputNumber, amount]. @p{par} Create a raw transaction to spend, using createrawtx. @p{brk} Use signrawtx to add your signatures (after unlocking the wallet, if necessary). @p{brk} Give the transaction to the other person(s) to sign. @p{brk} You or they submit the transaction to the network using sendrawtx. @p{brk} I don't imagine anybody but very-early-adopters or ultra-geeks will do this by calling these RPC methods at a command-line. They are really intended for people writing services on top of bitcoind. The service should be careful to include an appropriate transaction fee, or the sendrawtx method is likely to fail. @p{par} I've been asked a couple of times: why doesn't signrawtx handle the BIP 0010 (@s{(link)}) transaction format? @p{par} I considered parsing/writing BIP 10 format for raw transactions, but decided that reading/writing BIP 10 format should happen at a higher level and not in the low-level RPC calls. So 'raw transactions' are simply hex-encoded into JSON strings, and encoding/decoding them is just a couple of lines of already-written-and-debugged code. @p{par} @p{@p{--}-}@p{@p{--}-} @p{par} Here is the help output and example use for all the new RPC calls: @p{par} listunspent [minconf=1] [maxconf=999999] @p{brk} Returns array of unspent transaction outputs @p{brk} with between minconf and maxconf (inclusive) confirmations. @p{brk} Returns an array of 4-element arrays, each of which is: @p{brk} [transaction id, output, amount, confirmations] @p{par} E.g: listunspent 1 2 @p{brk} Returns: @p{brk} [ @p{brk} [ @p{brk} "2881b33a8c0bbdb45b0a65b36aa6611a05201e316ea3ad718762d48ef9588fb3", @p{brk} 0, @p{brk} 40.00000000, @p{brk} 2 @p{brk} ], @p{brk} [ @p{brk} "894a0fc535c7b49f434ceb633d8555ea24c8f9775144efb42da85b853280bcd7", @p{brk} 0, @p{brk} 50.00000000, @p{brk} 1 @p{brk} ] @p{brk} ] @p{par} getrawtx @p{lt}txid@s{gt} @p{brk} Returns hexadecimal-encoded, serialized transaction data @p{brk} for @p{lt}txid@s{gt}. Returns an error if @p{lt}txid@s{gt} is unknown. @p{par} E.g.: getrawtx fce46ea2448820f7bb8091b5f5e3fd75b7b267e60b9a22af88a9eeabfb084233 @p{brk} Returns: @p{brk} 01000000016d40da062b6a0edcaf643b6e25b943baf103941589d287e39d6f425d84ae8b1c000000004847304402203fb648ff8381d8961e66ef61ab88afe52826a5179b8a7312742c8d93785ca56302204240ea12de1211fffab49686f13ca0e78011d1985765be6e6aa8e747852f897d01ffffffff0100f2052a0100000017a914f96e358e80e8b3660256b211a23ce3377d2f9cb18700000000 @p{par} @p{brk} createrawtx [["txid",n],...] {address:amount,...} @p{brk} Create a transaction spending given inputs @p{brk} (array of (hex transaction id, output number) pairs), @p{brk} sending to given address(es). @p{brk} Returns the same information as gettransaction, plus an @p{brk} extra "rawtx" key with the hex-encoded transaction. @p{brk} Note that the transaction's inputs are not signed, and @p{brk} it is not stored in the wallet or transmitted to the network. @p{par} E.g.: createrawtx '[ ["fce46ea2448820f7bb8091b5f5e3fd75b7b267e60b9a22af88a9eeabfb084233",0] ]' '{"mqYmZSQQuAWNQcdwBrDwmtTXg2TLNz748L":50}' @p{brk} Returns: @p{brk} { @p{brk} "version" : 1, @p{brk} "locktime" : 0, @p{brk} "size" : 85, @p{brk} "vin" : [ @p{brk} { @p{brk} "prevout" : { @p{brk} "hash" : "fce46ea2448820f7bb8091b5f5e3fd75b7b267e60b9a22af88a9eeabfb084233", @p{brk} "n" : 0 @p{brk} }, @p{brk} "scriptSig" : "", @p{brk} "sequence" : 4294967295 @p{brk} } @p{brk} ], @p{brk} "vout" : [ @p{brk} { @p{brk} "value" : 50.00000000, @p{brk} "scriptPubKey" : "OP_DUP OP_HASH160 6e0920fc26383dc7e6101bc417cf87169d0cedbd OP_EQUALVERIFY OP_CHECKSIG" @p{brk} } @p{brk} ], @p{brk} "rawtx" : "0100000001334208fbabeea988af229a0be667b2b775fde3f5b59180bbf7208844a26ee4fc0000000000ffffffff0100f2052a010000001976a9146e0920fc26383dc7e6101bc417cf87169d0cedbd88ac00000000" @p{brk} } @p{par} signrawtx @p{lt}hex string@s{gt} [@p{lt}prevtx1@s{gt},@p{lt}prevtx2@s{gt}...] @p{brk} Sign inputs for raw transaction (serialized, hex-encoded). @p{brk} Second argument is an array of raw previous transactions that @p{brk} this transaction depends on but are not yet in the blockchain. @p{brk} Returns json object with keys: @p{brk} rawtx : raw transaction with signature(s) (hex-encoded string) @p{brk} complete : 1 if transaction has a complete set of signature (0 if not) @p{par} E.g.: signrawtx "0100000001334208fbabeea988af229a0be667b2b775fde3f5b59180bbf7208844a26ee4fc0000000000ffffffff0100f2052a010000001976a9146e0920fc26383dc7e6101bc417cf87169d0cedbd88ac00000000" '["01000000016d40da062b6a0edcaf643b6e25b943baf103941589d287e39d6f425d84ae8b1c000000004847304402203fb648ff8381d8961e66ef61ab88afe52826a5179b8a7312742c8d93785ca56302204240ea12de1211fffab49686f13ca0e78011d1985765be6e6aa8e747852f897d01ffffffff0100f2052a0100000017a914f96e358e80e8b3660256b211a23ce3377d2f9cb18700000000"]' @p{brk} Returns: @p{brk} { @p{brk} "rawtx" : "0100000001334208fbabeea988af229a0be667b2b775fde3f5b59180bbf7208844a26ee4fc000000009100473044022007f3ba1b8bdc156f2340ef1222eb287c3f5481a8078a8dad43aa09fd289ba19002201cc72e97406d546dc918159978dc78aee8215a6418375956665ee44e6eacc1150147522102894ca6e7a6483d0f8fa6110c77c431035e8d462e3a932255d9dda65e8fada55c2103c556ef01e89a07ee9ba61581658fa007bf442232daed8b465c47c278550d3dab52aeffffffff0100f2052a010000001976a9146e0920fc26383dc7e6101bc417cf87169d0cedbd88ac00000000", @p{brk} "complete" : false @p{brk} } @p{par} sendrawtx @p{lt}hex string@s{gt} @p{brk} Submits raw transaction (serialized, hex-encoded) to local node and network. @p{brk} E.g.: sendrawtx 0100000001334208fbabeea988af229a0be667b2b775fde3f5b59180bbf7208844a26ee4fc000000009100473044022007f3ba1b8bdc156f2340ef1222eb287c3f5481a8078a8dad43aa09fd289ba19002201cc72e97406d546dc918159978dc78aee8215a6418375956665ee44e6eacc1150147522102894ca6e7a6483d0f8fa6110c77c431035e8d462e3a932255d9dda65e8fada55c2103c556ef01e89a07ee9ba61581658fa007bf442232daed8b465c47c278550d3dab52aeffffffff0100f2052a010000001976a9146e0920fc26383dc7e6101bc417cf87169d0cedbd88ac00000000 @p{brk} Returns: @p{brk} error: {"code":-22,"message":"TX rejected"} @p{par} (Rejected because it doesn't have all required signatures, if it was accepted it would return the transaction id) @p{brk}