Bitcoin Forum
May 11, 2024, 09:25:21 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help with error code -22: Previous output scriptPubKey mismatch  (Read 611 times)
687_2 (OP)
Full Member
***
Offline Offline

Activity: 173
Merit: 105



View Profile
March 03, 2017, 11:30:48 AM
Merited by ABCbits (1)
 #1

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
[
  {
    "txid": "0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768",
    "vout": 0,
    "address": "13m5CWgygXuCbwuMo6MFtqNsiZT8uY1o6Q",
    "account": "",
    "scriptPubKey": "76a9141e460f008264743caa92c9d23f944216fd29c7a788ac",
    "amount": 0.00039000,
    "confirmations": 21,
    "spendable": true,
    "solvable": true
  }
]

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:

687_2$ bitcoin-cli signrawtransaction '010000000168c7a2d220b87288c9502ac4a04fda2413dbe5ce723f1e84571e67fc7a50530d0100000000ffffffff0270940000000000001976a914963d0a59d3b0ccfd0df3c95c972bee98e06ba19688ac581b0000000000001976a914356242ba76e9e8df980ac9d2d5399dee1233e45488ac00000000' '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":1,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]'

This results in the error:
Code:
error code: -22
error message:
Previous output scriptPubKey mismatch:
OP_DUP OP_HASH160 cbe0394e3f79b2f4f4e87191c638df0e8795bf92 OP_EQUALVERIFY OP_CHECKSIG
vs:
OP_DUP OP_HASH160 1e460f008264743caa92c9d23f944216fd29c7a7 OP_EQUALVERIFY OP_CHECKSIG

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?


Buy the dip with the security and privacy of your own wallet: use cross chain atomic swaps to trade Bitcoin, USDT, and Ether. Trades are secured and settled on-chain. https://sibex.io
1715419521
Hero Member
*
Offline Offline

Posts: 1715419521

View Profile Personal Message (Offline)

Ignore
1715419521
Reply with quote  #2

1715419521
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715419521
Hero Member
*
Offline Offline

Posts: 1715419521

View Profile Personal Message (Offline)

Ignore
1715419521
Reply with quote  #2

1715419521
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
March 03, 2017, 02:13:11 PM
 #2

Then I create the raw transaction:

Code:
bitcoin-cli createrawtransaction '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":1,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]' '{"1EhPUwR9BkWWJ1K9rWjxSFbBMGKXKozCim":0.00038,"15sGXSMk99DUzwPMXqCevYB1gmS3c62CQr":0.00007}'

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.

Ok, now I want to sign the transaction. I format the command as prescribed:
Code:

687_2$ bitcoin-cli signrawtransaction '010000000168c7a2d220b87288c9502ac4a04fda2413dbe5ce723f1e84571e67fc7a50530d0100000000ffffffff0270940000000000001976a914963d0a59d3b0ccfd0df3c95c972bee98e06ba19688ac581b0000000000001976a914356242ba76e9e8df980ac9d2d5399dee1233e45488ac00000000' '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":1,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]'
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.

elbandi
Hero Member
*****
Offline Offline

Activity: 525
Merit: 529


View Profile
March 03, 2017, 02:22:04 PM
 #3

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
[
  {
    "txid": "0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768",
    "vout": 0,
    "address": "13m5CWgygXuCbwuMo6MFtqNsiZT8uY1o6Q",
    "account": "",
    "scriptPubKey": "76a9141e460f008264743caa92c9d23f944216fd29c7a788ac",
    "amount": 0.00039000,
    "confirmations": 21,
    "spendable": true,
    "solvable": true
  }
]

Then I create the raw transaction:

Code:
bitcoin-cli createrawtransaction '[{"txid":"0d53507afc671e57841e3f72cee5db1324da4fa0c42a50c98872b820d2a2c768","vout":1,"scriptPubKey":"76a9141e460f008264743caa92c9d23f944216fd29c7a788ac"}]' '{"1EhPUwR9BkWWJ1K9rWjxSFbBMGKXKozCim":0.00038,"15sGXSMk99DUzwPMXqCevYB1gmS3c62CQr":0.00007}'

you used wrong vout index. in listunspent, vout index is 0, in your command line vout is 1.
and remove scriptPubKey param, no need that
687_2 (OP)
Full Member
***
Offline Offline

Activity: 173
Merit: 105



View Profile
March 04, 2017, 04:51:30 PM
 #4

Thanks guys, but now I have this problem:

Code:
error code: -3
error message:
Missing scriptPubKey

Code:
error code: -8
error message:
Invalid parameter, missing vout key

 Huh

Buy the dip with the security and privacy of your own wallet: use cross chain atomic swaps to trade Bitcoin, USDT, and Ether. Trades are secured and settled on-chain. https://sibex.io
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
March 04, 2017, 04:59:34 PM
 #5

Thanks guys, but now I have this problem:

Code:
error code: -3
error message:
Missing scriptPubKey

Code:
error code: -8
error message:
Invalid parameter, missing vout key

 Huh
For which command is each error being returned?

687_2 (OP)
Full Member
***
Offline Offline

Activity: 173
Merit: 105



View Profile
March 04, 2017, 05:01:44 PM
 #6

The error is always thrown with bitcoin-cli signrawtransaction

createrawtransaction always generates a nice hash:

Code:
010000000168c7a2d220b87288c9502ac4a04fda2413dbe5ce723f1e84571e67fc7a50530d0100000000ffffffff0230750000000000001976a914963d0a59d3b0ccfd0df3c95c972bee98e06ba19688ac401f0000000000001976a9145112f7d2f5818bc8c1921e3181f2d27822feafb388ac00000000

Buy the dip with the security and privacy of your own wallet: use cross chain atomic swaps to trade Bitcoin, USDT, and Ether. Trades are secured and settled on-chain. https://sibex.io
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
March 04, 2017, 05:17:27 PM
 #7

The error is always thrown with bitcoin-cli signrawtransaction
Interesting. Try using your original signrawtransaction command but with "vout":0 instead of "vout":1

createrawtransaction 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.

687_2 (OP)
Full Member
***
Offline Offline

Activity: 173
Merit: 105



View Profile
March 05, 2017, 10:33:06 AM
 #8

Quote
The error is always thrown with bitcoin-cli signrawtransaction
Interesting. Try using your original signrawtransaction command but with "vout":0 instead of "vout":1

Success! 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:
{
  "hex": "010000000168c7a2d220b87288c9502ac4a04fda2413dbe5ce723f1e84571e67fc7a50530d000000006b483045022100be8112238a16d24ccc1769f98d5df7ec508f99eaf6b97ec42dcece8b9360328402207c07a830266c34aa77d1612e04d90757f8149d4df4785ada8cf957334497878b01210285019768580fb3d7d37928993b17e951527e5c2c2084a78013248e8fe572acecffffffff0230750000000000001976a914963d0a59d3b0ccfd0df3c95c972bee98e06ba19688ac401f0000000000001976a9145112f7d2f5818bc8c1921e3181f2d27822feafb388ac00000000",
  "complete": true
}

Buy the dip with the security and privacy of your own wallet: use cross chain atomic swaps to trade Bitcoin, USDT, and Ether. Trades are secured and settled on-chain. https://sibex.io
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!