<h2>Answering my own question</h2>

<p>Two things basically got into way of creating and signing a raw bitcoin transaction using 'bitcoind' program:</p>

<ul>
<li>Leaving 'redeemScript' to be the empty string
<ul>
<li>It has to be empty for simple bitcoin transaction!</li>
</ul></li>
<li>Using single-quote mark (') to make the bitcoin RPC call looking nice and not messy.</li>
</ul>

<p>That's all.</p>

CC BY-SA 3.0
2014-08-10T09:51:39.420Z
2014-08-10T09:51:39.420Z
KostaZ
<p>I want to create and sign bitcoin transaction <strong>using only 'bitcoind' and 'bitcoin-cli'</strong>.</p>

<p>I can create a transaction using <strong>createrawtransaction</strong> RPC API, but signing it using 'signrawtransaction' fails.</p>

<p><strong>UPDATE</strong>: <em>I figured it out and answered myself below. Take care to have scriptPubKey correct and leave redeemScript empty for simple transactions.</em></p>

<p>The private key is not stored in <strong>bitcoind</strong>'s built-in wallet. That is, private / public key pair was created by vanity utility (for example).</p>

<h2>Setup</h2>

<ul>
<li>"from" address": <code>1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD</code> (<code>From_Addr_1As</code>)</li>
<li>"to" address:    <code>1Mu5S5fuztimKZizvYZjKwpYfM9ZFf7zmo</code> (<code>To_Addr_1Mu</code>)</li>
<li>transaction that sent funds to <code>From_Addr_1As</code>: <code>4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e</code> (<code>Prev_Tx_4325</code>)</li>
<li>new transaction is <code>New_Tx</code></li>
</ul>

<h2>Funding</h2>

<p>The transaction (<code>Prev_Tx_4325</code>) sent 0.00187 BTC to <code>From_Addr_1As</code>:
<a href="https://blockchain.info/tx/4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e" rel="noreferrer">https://blockchain.info/tx/4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e</a> - also seen in the address transaction view <a href="https://blockchain.info/address/1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD" rel="noreferrer">https://blockchain.info/address/1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD</a></p>

<p>I want to send 0.00186 BTC from <code>From_Addr_1As</code> to <code>To_Addr_1Mu</code>.
The 0.00001 BTC fee included.</p>

<h2>Bash Shell: Create Raw Transaction (successful):</h2>

<p><code>$ ./bitcoin-cli -rpcpassword=123456 createrawtransaction '[{"txid":"4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e","vout":0}]' '{"1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD":0.00186}'</code></p>

<p>Command output:</p>

<p><code>01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba525430000000000ffffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000</code></p>

<h2>Bash Shell: Decode Raw Transaction (successful):</h2>

<p>Pay attention: 'scriptSig' is empty!</p>

<p><code>$ ./bitcoin-cli -rpcpassword=123456 decoderawtransaction 01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba525430000000000ffffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000</code></p>

<p>Command output:</p>

<p><code>{
    "txid" : "b1ff3da36a6d7c3aaaee41428a7e239baa6243e37d7e1db60ea022d9f994ec52",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "txid" : "4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "",
                "hex" : ""
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 0.00186000,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 01ddbca1a39b60b54fb671297a4a20a7681e0171 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD"
                ]
            }
        }
    ]
}
</code></p>

<h2>Bash Shell: Sign Raw Transaction (successful):</h2>

<p>Pay attention:</p>

<ul>
<li><code>scriptPubKey</code> is copied from the <code>Prev_Tx_4325</code></li>
<li><code>redeemScript</code> is left empty string: ""</li>
</ul>

<p><code>./bitcoin-cli -rpcpassword=123456 signrawtransaction "01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba525430000000000ffffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000" '[{"txid":"4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e","vout":0,"scriptPubKey":"76a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac","redeemScript":""}]' '["5J34hLVaP9UAj4BcdbgYoPia93zzDfo8JhTzUN2tf8qqRiZqtjY"]' "ALL"</code></p>

<p>Command output:</p>

<p><code>{
    "hex" : "01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba52543000000008a47304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a014104aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4affffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000",
    "complete" : true
}</code></p>

<h2>Bash Shell: Decode signed transaction (successful):</h2>

<p><code>$ ./bitcoin-cli -rpcpassword=123456 decoderawtransaction 01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba52543000000008a47304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a014104aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4affffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000</code></p>

<p>Command output:</p>

<p><code>{
    "txid" : "267550934eb413a623459464d88cb14ff47fa192df720cf8485b590812db8fba",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "txid" : "4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a01 04aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4a",
                "hex" : "47304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a014104aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4a"
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 0.00186000,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 01ddbca1a39b60b54fb671297a4a20a7681e0171 OP_EQUALVERIFY OP_CHECKSIG",
                "hex" : "76a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD"
                ]
            }
        }
    ]
}</code></p>

<h2>Bash Shell: Send Raw Transaction (successful):</h2>

<p><code>./bitcoin-cli -rpcpassword=123456 sendrawtransaction 01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba52543000000008a47304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a014104aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4affffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000
267550934eb413a623459464d88cb14ff47fa192df720cf8485b590812db8fba</code></p>

<p>Command output:
No output on command success!</p>

<h1>Conclusion  :-)</h1>

<p>By explaining and formulating the question I found a solution. It is really worth asking on StackExchange, and I got to the answer by myself!</p>

<p><strong>UPDATE</strong>: <em>Thanks for comments - I answered myself below. Ensure scriptPubKey is correct and leave redeemScript empty for simple transactions.</em></p>

CC BY-SA 3.0
2014-08-09T18:14:04.610Z
What is the question?
Pieter Wuille
CC BY-SA 3.0
2014-08-09T20:07:07.467Z
Ask the question and then answer it by yourself instead of putting the question and the answer in the "question"
Jan Moritz
CC BY-SA 3.0
2014-08-10T01:31:40.830Z
As @JanMoritzLindemann already suggested, your post doesn't fit our format. Please separate it into a question and an answer. You can find a visual explanation of the Stackexchange format in our [About].
Murch
<transactions><bitcoind><signature><bitcoin-cli>
How to sign bitcoin transaction with 'bitcoind' and non-bitcoind-wallet private key?
KostaZ
# How to sign bitcoin transaction with 'bitcoind' and non-bitcoind-wallet private key?

(Asked by: username_0 on 2014-08-09)

I want to create and sign bitcoin transaction **using only 'bitcoind' and 'bitcoin-cli'**.

I can create a transaction using **createrawtransaction** RPC API, but signing it using 'signrawtransaction' fails.

**UPDATE**: *I figured it out and answered myself below. Take care to have scriptPubKey correct and leave redeemScript empty for simple transactions.*

The private key is not stored in **bitcoind**'s built-in wallet. That is, private / public key pair was created by vanity utility (for example).

## Setup

* "from" address": `1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD` (`From_Addr_1As`)
* "to" address: `1Mu5S5fuztimKZizvYZjKwpYfM9ZFf7zmo` (`To_Addr_1Mu`)
* transaction that sent funds to `From_Addr_1As`: `4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e` (`Prev_Tx_4325`)
* new transaction is `New_Tx`

## Funding

The transaction (`Prev_Tx_4325`) sent 0.00187 BTC to `From_Addr_1As`:
<https://blockchain.info/tx/4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e> - also seen in the address transaction view <https://blockchain.info/address/1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD>

I want to send 0.00186 BTC from `From_Addr_1As` to `To_Addr_1Mu`.
The 0.00001 BTC fee included.

## Bash Shell: Create Raw Transaction (successful):

`$ ./bitcoin-cli -rpcpassword=123456 createrawtransaction '[{"txid":"4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e","vout":0}]' '{"1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD":0.00186}'`

Command output:

`01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba525430000000000ffffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000`

## Bash Shell: Decode Raw Transaction (successful):

Pay attention: 'scriptSig' is empty!

`$ ./bitcoin-cli -rpcpassword=123456 decoderawtransaction 01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba525430000000000ffffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000`

Command output:

`{
"txid" : "b1ff3da36a6d7c3aaaee41428a7e239baa6243e37d7e1db60ea022d9f994ec52",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e",
"vout" : 0,
"scriptSig" : {
"asm" : "",
"hex" : ""
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.00186000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 01ddbca1a39b60b54fb671297a4a20a7681e0171 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD"
]
}
}
]
}`

## Bash Shell: Sign Raw Transaction (successful):

Pay attention:

* `scriptPubKey` is copied from the `Prev_Tx_4325`
* `redeemScript` is left empty string: ""

`./bitcoin-cli -rpcpassword=123456 signrawtransaction "01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba525430000000000ffffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000" '[{"txid":"4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e","vout":0,"scriptPubKey":"76a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac","redeemScript":""}]' '["5J34hLVaP9UAj4BcdbgYoPia93zzDfo8JhTzUN2tf8qqRiZqtjY"]' "ALL"`

Command output:

`{
"hex" : "01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba52543000000008a47304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a014104aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4affffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000",
"complete" : true
}`

## Bash Shell: Decode signed transaction (successful):

`$ ./bitcoin-cli -rpcpassword=123456 decoderawtransaction 01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba52543000000008a47304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a014104aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4affffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000`

Command output:

`{
"txid" : "267550934eb413a623459464d88cb14ff47fa192df720cf8485b590812db8fba",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "4325a5db66cbc8e9ff6a585cd0e8a2288ea74f9b46d2972b93f63bbb7d09a23e",
"vout" : 0,
"scriptSig" : {
"asm" : "304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a01 04aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4a",
"hex" : "47304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a014104aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4a"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.00186000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 01ddbca1a39b60b54fb671297a4a20a7681e0171 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1AsJjnWg5QKBThM6mK9jZ8mmo6KUzDjRD"
]
}
}
]
}`

## Bash Shell: Send Raw Transaction (successful):

`./bitcoin-cli -rpcpassword=123456 sendrawtransaction 01000000013ea2097dbb3bf6932b97d2469b4fa78e28a2e8d05c586affe9c8cb66dba52543000000008a47304402206f40f4eb8c6cab7c6dd45a132d437e736a6a0dddfb2b78b10e6efbcaf61592f602200d329a57d7a0c969cc349f41852da4ba1a3bc2245e656bdd41780455b97bf84a014104aa49fbe6608076318ff09171e3c2b4a2effa52d53a417371140642996693ae3ac53ce300fff7fef650d0a2418b087a237aa6838eed3bdfad0ec0069df7209f4affffffff0190d60200000000001976a91401ddbca1a39b60b54fb671297a4a20a7681e017188ac00000000
267550934eb413a623459464d88cb14ff47fa192df720cf8485b590812db8fba`

Command output:
No output on command success!

# Conclusion :-)

By explaining and formulating the question I found a solution. It is really worth asking on StackExchange, and I got to the answer by myself!

**UPDATE**: *Thanks for comments - I answered myself below. Ensure scriptPubKey is correct and leave redeemScript empty for simple transactions.*

**Tags:** transactions, bitcoind, signature, bitcoin-cli

> **Comments:**
> **username_1**: What is the question?  
> **username_2**: Ask the question and then answer it by yourself instead of putting the question and the answer in the "question"  
> **username_3**: As @JanMoritzLindemann already suggested, your post doesn't fit our format. Please separate it into a question and an answer. You can find a visual explanation of the Stackexchange format in our [About].  

---

## 1 answers

### Answer by username_0 on 2014-08-10. Score: 5 | Accepted answer

## Answering my own question

Two things basically got into way of creating and signing a raw bitcoin transaction using 'bitcoind' program:

* Leaving 'redeemScript' to be the empty string
  + It has to be empty for simple bitcoin transaction!
* Using single-quote mark (') to make the bitcoin RPC call looking nice and not messy.

That's all.


---

