Title: Help with error code -22: Previous output scriptPubKey mismatch Post by: 687_2 on March 03, 2017, 11:30:48 AM Hi all,
I'm trying to create a raw transaction using bitcoin-cli. First I look at the transaction: Code: 687_2$ bitcoin-cli listunspent Then I create the raw transaction: Code: bitcoin-cli createrawtransaction '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":1,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]' '{"1EhPUwR9BkWWJ1K9rWjxSFbBMGKXKozCim":0.00038,"15sGXSMk99DUzwPMXqCevYB1gmS3c62CQr":0.00007}' This gives me the hex: Code: 010000000168c7a2d220b87288c9502ac4a04fda2413dbe5ce723f1e84571e67fc7a50530d0100000000ffffffff0270940000000000001976a914963d0a59d3b0ccfd0df3c95c972bee98e06ba19688ac581b0000000000001976a914356242ba76e9e8df980ac9d2d5399dee1233e45488ac00000000 Ok, now I want to sign the transaction. I format the command as prescribed: Code:
This results in the error: Code: error code: -22 I've tried a few different ways of breaking this, looked here: https://www.reddit.com/r/Bitcoin/comments/2ebaow/how_to_create_a_raw_transaction_in_bitcoin_qt/ which doesn't seem to help, and I tried Greg's example: https://people.xiph.org/~greg/signdemo.txt as well; that one worked but I couldn't send the raw transaction (insufficient fee, or something. It made sense). This seems like a trivial issue, maybe I've just been looking at my monitor too long. Does anyone see what I'm doing wrong? Is there something I'm missing? Title: Re: Help with error code -22: Previous output scriptPubKey mismatch Post by: achow101 on March 03, 2017, 02:13:11 PM Then I create the raw transaction: There is no need to specify the scriptPubKey in this command. It is not used for creating raw unsigned transactions and is not even a parameter of createrawtransaction.Code: bitcoin-cli createrawtransaction '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":1,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]' '{"1EhPUwR9BkWWJ1K9rWjxSFbBMGKXKozCim":0.00038,"15sGXSMk99DUzwPMXqCevYB1gmS3c62CQr":0.00007}' Ok, now I want to sign the transaction. I format the command as prescribed: Since the transaction you are spending from is in your wallet, there is no need to specify the prevouts. Just run the command with only the raw unsigned transaction from createrawtransaction and the wallet will handle the rest.Code:
Title: Re: Help with error code -22: Previous output scriptPubKey mismatch Post by: elbandi on March 03, 2017, 02:22:04 PM Hi all, you used wrong vout index. in listunspent, vout index is 0, in your command line vout is 1.I'm trying to create a raw transaction using bitcoin-cli. First I look at the transaction: Code: 687_2$ bitcoin-cli listunspent Then I create the raw transaction: Code: bitcoin-cli createrawtransaction '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":1,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]' '{"1EhPUwR9BkWWJ1K9rWjxSFbBMGKXKozCim":0.00038,"15sGXSMk99DUzwPMXqCevYB1gmS3c62CQr":0.00007}' and remove scriptPubKey param, no need that Title: Re: Help with error code -22: Previous output scriptPubKey mismatch Post by: 687_2 on March 04, 2017, 04:51:30 PM Thanks guys, but now I have this problem:
Code: error code: -3 Code: error code: -8 ??? Title: Re: Help with error code -22: Previous output scriptPubKey mismatch Post by: achow101 on March 04, 2017, 04:59:34 PM Thanks guys, but now I have this problem: For which command is each error being returned?Code: error code: -3 Code: error code: -8 ??? Title: Re: Help with error code -22: Previous output scriptPubKey mismatch Post by: 687_2 on March 04, 2017, 05:01:44 PM The error is always thrown with bitcoin-cli signrawtransaction
createrawtransaction always generates a nice hash: Code: 010000000168c7a2d220b87288c9502ac4a04fda2413dbe5ce723f1e84571e67fc7a50530d0100000000ffffffff0230750000000000001976a914963d0a59d3b0ccfd0df3c95c972bee98e06ba19688ac401f0000000000001976a9145112f7d2f5818bc8c1921e3181f2d27822feafb388ac00000000 Title: Re: Help with error code -22: Previous output scriptPubKey mismatch Post by: achow101 on March 04, 2017, 05:17:27 PM The error is always thrown with bitcoin-cli signrawtransaction Interesting. Try using your original signrawtransaction command but with "vout":0 instead of "vout":1createrawtransaction always generates a nice hash: Createrawtransaction does not generate a hash. It creates a raw transaction. Just because something is displayed in hex does not mean that it s a hash.Title: Re: Help with error code -22: Previous output scriptPubKey mismatch Post by: 687_2 on March 05, 2017, 10:33:06 AM Quote The error is always thrown with bitcoin-cli signrawtransaction Interesting. Try using your original signrawtransaction command but with "vout":0 instead of "vout":1Success! I finally got signrawtransaction to sign the raw transaction, thank you! Here's my code to create the raw transaction: Code: bitcoin-cli createrawtransaction '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":0,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]' '{"1EhPUwR9BkWWJ1K9rWjxSFbBMGKXKozCim":0.0003,"18PgTTpQP9snFrJfZk8KCHKEXP9uUX7jLW":0.00008}' It outputs the hash, and I copy and paste that hash into the signrawtransaction command. Now signing: Code: 687_2$ bitcoin-cli signrawtransaction '010000000168c7a2d220b87288c9502ac4a04fda2413dbe5ce723f1e84571e67fc7a50530d0000000000ffffffff0230750000000000001976a914963d0a59d3b0ccfd0df3c95c972bee98e06ba19688ac401f0000000000001976a9145112f7d2f5818bc8c1921e3181f2d27822feafb388ac00000000' '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":0,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]' '["myprivatekey"]' Output: Code: { |