Creating a Raw Transaction - Discussion

when adding more fields I get this:

bitcoin-cli -regtest signrawtransactionwithwallet $RAW_TX '''
>     [
>       {
>         "txid": "'$UTXO1_TXID'",
>         "vout": '$UTXO1_VOUT',
>         "scriptPubKey": "'$UTXO1_OUTPUT_SCRIPT'",
>         "value": '$UTXO1_VALUE'
>       }
>     ]'''
error code: -3
error message:
Missing amount for CTxOut(nValue=21000000.00000000, scriptPubKey=001492718ece477c2053ebee50dc7e)

Did you replace the $ variables (RAW_TX, UTXO1_TXID, UTXO1_VOUT, UTXO1_OUTPUT_SCRIPT and UTXO1_VALUE) with actual values or is this what you are using to create the tx?

Yes I stored the values first, for example UTXO1_TXID=12345

Hey Flip for some reason no matter how I adjust fees, I can’t seem to send the raw transaction. I also set PS C:\Program Files\Bitcoin\daemon> ./bitcoind -regtest -fallbackfee=0
-not sure if setgwit is messing with it? Or if its just being finicky? Thanks for any help!

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest sendrawtransaction “02000000000101a7aa465852e3802d20f68d013faa9372f35297596997d63cb58666665f2764610000000000ffffffff0100ca9a3b0000000016001463eee6cb879c3336eaff118a9619ec267fb40df30247304402201b11ffab4576b01918c0274d4a7e8514fe98d3bc5cb80b6093ef5e6b7389ddbf02205ea18d7c37fce24e218b1d5d2f55eac92627624e063728dc6dc0d3332fba8b3f01210294a6bc4e2f304e193d3e48fea922ca37f383294aa78cb3dd8aa0b1afd6ef2f4c00000000”
error code: -25
error message:
Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest getrawchangeaddress
bcrt1qrauldp9xqxr2xacngxgqg5z04v6da978uj6ks4

{“bcrt1qv0hwdju8nsend6hlzx9fvx0vyelmgr0n8zrmec”:10, "bcrt1qrauldp9xqxr2xacngxgqg5z04v6da978uj6ks4:
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest createrawtransaction ‘[{“txid”: “6164275f666686b53cd69769599752f37293aa3f018df6202d80e3525846aaa7”,“vout”:0}]’ ‘{“bcrt1qv0hwdju8nsend6hlzx9fvx0vyelmgr0n8zrmec”:10, “bcrt1qrauldp9xqxr2xacngxgqg5z04v6da978uj6ks4”: 0.001}’
0200000001a7aa465852e3802d20f68d013faa9372f35297596997d63cb58666665f2764610000000000ffffffff0200ca9a3b0000000016001463eee6cb879c3336eaff118a9619ec267fb40df3a0860100000000001600141f79f684a60186a37713419004504fab34de97c700000000
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest signrawtransactionwithwallet 0200000001a7aa465852e3802d20f68d013faa9372f35297596997d63cb58666665f2764610000000000ffffffff0200ca9a3b0000000016001463eee6cb879c3336eaff118a9619ec267fb40df3a0860100000000001600141f79f684a60186a37713419004504fab34de97c700000000
{
“hex”: “02000000000101a7aa465852e3802d20f68d013faa9372f35297596997d63cb58666665f2764610000000000ffffffff0200ca9a3b0000000016001463eee6cb879c3336eaff118a9619ec267fb40df3a0860100000000001600141f79f684a60186a37713419004504fab34de97c7024730440220015816ca25b348313b0388da553c82b98433f4fb9a7976dc76fac066669fc6320220475efa59eb0c5e39d1b7fad519fb5892fda39fbbcab2e109b5819cf00928dd1201210294a6bc4e2f304e193d3e48fea922ca37f383294aa78cb3dd8aa0b1afd6ef2f4c00000000”,
“complete”: true

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest sendrawtransaction 02000000000101a7aa465852e3802d20f68d013faa9372f35297596997d63cb58666665f2764610000000000ffffffff0200ca9a3b0000000016001463eee6cb879c3336eaff118a9619ec267fb40df3a0860100000000001600141f79f684a60186a37713419004504fab34de97c7024730440220015816ca25b348313b0388da553c82b98433f4fb9a7976dc76fac066669fc6320220475efa59eb0c5e39d1b7fad519fb5892fda39fbbcab2e109b5819cf00928dd1201210294a6bc4e2f304e193d3e48fea922ca37f383294aa78cb3dd8aa0b1afd6ef2f4c00000000
error code: -25
error message:
Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest signrawtransactionwithwallet 02000000000101a7aa465852e3802d20f68d013faa9372f35297596997d63cb58666665f2764610000000000ffffffff0200ca9a3b0000000016001463eee6cb879c3336eaff118a9619ec267fb40df3a0860100000000001600141f79f684a60186a37713419004504fab34de97c7024730440220015816ca25b348313b0388da553c82b98433f4fb9a7976dc76fac066669fc6320220475efa59eb0c5e39d1b7fad519fb5892fda39fbbcab2e109b5819cf00928dd1201210294a6bc4e2f304e193d3e48fea922ca37f383294aa78cb3dd8aa0b1afd6ef2f4c00000000
{
“hex”: “02000000000101a7aa465852e3802d20f68d013faa9372f35297596997d63cb58666665f2764610000000000ffffffff0200ca9a3b0000000016001463eee6cb879c3336eaff118a9619ec267fb40df3a0860100000000001600141f79f684a60186a37713419004504fab34de97c7024730440220015816ca25b348313b0388da553c82b98433f4fb9a7976dc76fac066669fc6320220475efa59eb0c5e39d1b7fad519fb5892fda39fbbcab2e109b5819cf00928dd1201210294a6bc4e2f304e193d3e48fea922ca37f383294aa78cb3dd8aa0b1afd6ef2f4c00000000”,
“complete”: true
}
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest sendrawtransaction 02000000000101a7aa465852e3802d20f68d013faa9372f35297596997d63cb58666665f2764610000000000ffffffff0200ca9a3b0000000016001463eee6cb879c3336eaff118a9619ec267fb40df3a0860100000000001600141f79f684a60186a37713419004504fab34de97c7024730440220015816ca25b348313b0388da553c82b98433f4fb9a7976dc76fac066669fc6320220475efa59eb0c5e39d1b7fad519fb5892fda39fbbcab2e109b5819cf00928dd1201210294a6bc4e2f304e193d3e48fea922ca37f383294aa78cb3dd8aa0b1afd6ef2f4c00000000
error code: -25
error message:
Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)
PS C:\Program Files\Bitcoin\daemon>

The fee is implied as the difference between the inputs and outputs. You can create a new tx with lower fee or restart the daemon with maxtxfee set.

Hi @pmgoff, did you manage to resolve error 25? I’m stuck here too.

I comprehend the fee structure, but was unable after finish the raw transaction. I tried starting Bitcoind with a -fallbackfee of .001 (that seemed to resolve earlier issues was having with just sending a regulars trx from address to addrerss) I also tried setting the -fallbackfee=0. and in btc-cli I used “settxfee .001”. And still was getting maxtrxfee. If you read the createrawtransaction PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest createrawtransaction ‘[{“txid”: “6164275f666686b53cd69769599752f37293aa3f018df6202d80e3525846aaa7”,“vout”:0}]’ ‘{“bcrt1qv0hwdju8nsend6hlzx9fvx0vyelmgr0n8zrmec”:10, “bcrt1qrauldp9xqxr2xacngxgqg5z04v6da978uj6ks4”: 0.001}’ it’s set to .001 and the hex came back “complete”: true.
-There may be something in the btc-cli more recent update that may be in play?

isn’t it really the locking script we are generating by signing (rather than the unlocking script)… or maybe we should say “by signing we are generating the lockign script that will need to be unlocked by the receiver in the future if they want to spend” ?

I am on a different version of bitcoind as I installed via homebrew on mac. It looks like it is using segwit… so I run into an issue with the broadcast: **error code: -26** **error message:** **non-mandatory-script-verify-flag (Witness program hash mismatch)

any ideas?

Emmett@MDs-MacBook-Pro /u/l/o/bitcoin> bitcoin-cli -regtest decoderawtransaction 020000000150c77d28a5e3b6beb5cd37cc08058e9a608074b2d0cfb71d09ba2c7df4338e7b0000000000ffffffff01a086010000000000160014777b1d5fe7388ec4f83e45b3340141b564847a9200000000
{
  "txid": "f0aaa9ab32af5fc5db0e5254d7a00b9bfbcff4d1d2738cbb26b5ec3e49b8bb71",
  "hash": "f0aaa9ab32af5fc5db0e5254d7a00b9bfbcff4d1d2738cbb26b5ec3e49b8bb71",
  "version": 2,
  "size": 82,
  "vsize": 82,
  "weight": 328,
  "locktime": 0,
  "vin": [
    {
      "txid": "7b8e33f47d2cba091db7cfd0b27480609a8e0508cc37cdb5beb6e3a5287dc750",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 777b1d5fe7388ec4f83e45b3340141b564847a92",
        "hex": "0014777b1d5fe7388ec4f83e45b3340141b564847a92",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qwaa36hl88z8vf7p7gkengq2pk4jgg75jv7fet0"
        ]
      }
    }
  ]
}
Emmett@MDs-MacBook-Pro /u/l/o/bitcoin>
Emmett@MDs-MacBook-Pro /u/l/o/bitcoin>
Emmett@MDs-MacBook-Pro /u/l/o/bitcoin>
Emmett@MDs-MacBook-Pro /u/l/o/bitcoin> bitcoin-cli -regtest sendrawtransaction 020000000150c77d28a5e3b6beb5cd37cc08058e9a608074b2d0cfb71d09ba2c7df4338e7b0000000000ffffffff01a086010000000000160014777b1d5fe7388ec4f83e45b3340141b564847a9200000000
**error code: -26**
**error message:**
**non-mandatory-script-verify-flag (Witness program hash mismatch)**
Emmett@MDs-MacBook-Pro /u/l/

All new versions of bitcoin create a segwit tx by default. It seems like you missed a step when creating your tx, it doesn’t seem to have a change output set.

I thought it didn’t strictly need a change output ? i.e. that it automatically uses whatever is left over as the fee?

signing doesnt seem to be filling in the scriptSig:

create a raw transaction

bitcoin-cli -regtest createrawtransaction '[{"txid" : "3341d9c785babbbc7af1d85493c4ba55edff41b4ff8489844f9c3ecdcb02f0fe","vout" : 0}]' '{"bcrt1qzlxnp6kh87m8zczdy7fjamy8ed66r5ecwjyqd3" : 0.00001, "bcrt1qfv6au9q2u2gmdf7q0059ls85detepmhrdp3k8s" : 0.01}'

0200000001fef002cbcd3e9c4f848984ffb441ffed55bac49354d8f17abcbbba85c7d941330000000000ffffffff02e80300000000000016001417cd30ead73fb671604d27932eec87cb75a1d33840420f00000000001600144b35de140ae291b6a7c07be85fc0f46e5790eee300000000


bitcoin-cli -regtest decoderawtransaction 0200000001fef002cbcd3e9c4f848984ffb441ffed55bac49354d8f17abcbbba85c7d941330000000000ffffffff02e80300000000000016001417cd30ead73fb671604d27932eec87cb75a1d33840420f00000000001600144b35de140ae291b6a7c07be85fc0f46e5790eee300000000


{
  "txid": "e13fb06c235a458cac144670cf245fc0f1e8b8b3352a708057c5446fd9b28f47",
  "hash": "e13fb06c235a458cac144670cf245fc0f1e8b8b3352a708057c5446fd9b28f47",
  "version": 2,
  "size": 113,
  "vsize": 113,
  "weight": 452,
  "locktime": 0,
  "vin": [
    {
      "txid": "3341d9c785babbbc7af1d85493c4ba55edff41b4ff8489844f9c3ecdcb02f0fe",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00001000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 17cd30ead73fb671604d27932eec87cb75a1d338",
        "hex": "001417cd30ead73fb671604d27932eec87cb75a1d338",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qzlxnp6kh87m8zczdy7fjamy8ed66r5ecwjyqd3"
        ]
      }
    },
    {
      "value": 0.01000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 4b35de140ae291b6a7c07be85fc0f46e5790eee3",
        "hex": "00144b35de140ae291b6a7c07be85fc0f46e5790eee3",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qfv6au9q2u2gmdf7q0059ls85detepmhrdp3k8s"
        ]
      }
    }
  ]
}



sign it:

bitcoin-cli -regtest signrawtransactionwithwallet 0200000001fef002cbcd3e9c4f848984ffb441ffed55bac49354d8f17abcbbba85c7d941330000000000ffffffff02e80300000000000016001417cd30ead73fb671604d27932eec87cb75a1d33840420f00000000001600144b35de140ae291b6a7c07be85fc0f46e5790eee300000000

{
  "hex": "02000000000101fef002cbcd3e9c4f848984ffb441ffed55bac49354d8f17abcbbba85c7d941330000000000ffffffff02e80300000000000016001417cd30ead73fb671604d27932eec87cb75a1d33840420f00000000001600144b35de140ae291b6a7c07be85fc0f46e5790eee30247304402200d9d7c05551740ce78d5ba54d62cf103a388c68ef7662a3e09a69e7b03681166022071456a90fd1ce149dd662d251b3a2dddbce3a52f52db1bb76f33fda34e441edb0121033430f2bdff5c1ddca22ba75402febb7e0671004ebbb6aef0582ee47b4590f33e00000000",
  "complete": true
}



Decode again 

Emmett@MDs-MacBook-Pro bitcoin % bitcoin-cli -regtest decoderawtransaction 0200000001fef002cbcd3e9c4f848984ffb441ffed55bac49354d8f17abcbbba85c7d941330000000000ffffffff02e80300000000000016001417cd30ead73fb671604d27932eec87cb75a1d33840420f00000000001600144b35de140ae291b6a7c07be85fc0f46e5790eee300000000
{
  "txid": "e13fb06c235a458cac144670cf245fc0f1e8b8b3352a708057c5446fd9b28f47",
  "hash": "e13fb06c235a458cac144670cf245fc0f1e8b8b3352a708057c5446fd9b28f47",
  "version": 2,
  "size": 113,
  "vsize": 113,
  "weight": 452,
  "locktime": 0,
  "vin": [
    {
      "txid": "3341d9c785babbbc7af1d85493c4ba55edff41b4ff8489844f9c3ecdcb02f0fe",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00001000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 17cd30ead73fb671604d27932eec87cb75a1d338",
        "hex": "001417cd30ead73fb671604d27932eec87cb75a1d338",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qzlxnp6kh87m8zczdy7fjamy8ed66r5ecwjyqd3"
        ]
      }
    },
    {
      "value": 0.01000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 4b35de140ae291b6a7c07be85fc0f46e5790eee3",
        "hex": "00144b35de140ae291b6a7c07be85fc0f46e5790eee3",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qfv6au9q2u2gmdf7q0059ls85detepmhrdp3k8s"
        ]
      }
    }
  ]
}


shouldnt script sig been filled in above ?


Now we need to broadcast the transaction: 


Emmett@MDs-MacBook-Pro bitcoin % bitcoin-cli -regtest sendrawtransaction 0200000001fef002cbcd3e9c4f848984ffb441ffed55bac49354d8f17abcbbba85c7d941330000000000ffffffff02e80300000000000016001417cd30ead73fb671604d27932eec87cb75a1d33840420f00000000001600144b35de140ae291b6a7c07be85fc0f46e5790eee300000000
error code: -26
error message:
non-mandatory-script-verify-flag (Witness program hash mismatch)

Yes, sorry you are correct. If you set up a large enough tx then you don’t have to set a change address. The CLI might complain if it notices the fee is absurdly large.

It seems you’re still using the unsigned hex from the transaction after you signed it. You have to used the larger signed transaction, the output from signrawtransactionwithwallet. :slight_smile:

# The same up to this point ...

$ bitcoin-cli signrawtransactionwithwallet 0200000001437888a6bb3d417796dfb5fa3a9a12015d6303fd89d929e23499e5c9ab4d94bb0000000000ffffffff01c0aff6290100000016001491ec81b14179fa240ce51dadb28530f8c22b20cf00000000
{
 "hex": "02000000000101437888a6bb3d417796dfb5fa3a9a12015d6303fd89d929e23499e5c9ab4d94bb0000000000ffffffff01c0aff6290100000016001491ec81b14179fa240ce51dadb28530f8c22b20cf02473044022062dd47592ec1e4704d43de4c866da6a9c00614b9c59046ce3e7de738f281292302203e419daa01806d5999540805c0705c6076dd7a548bd357801b81da089b272131012102fd2d821fc03cc96b651af392b63d89ff8d328ad9e631732b92dde52cd6ecf88e00000000",
 "complete": true
}

# Use the new signed serialized tx from signrawtransactionwithwallet
$ bitcoin-cli decoderawtransaction 02000000000101437888a6bb3d417796dfb5fa3a9a12015d6303fd89d929e23499e5c9ab4d94bb0000000000ffffffff01c0aff6290100000016001491ec81b14179fa240ce51dadb28530f8c22b20cf02473044022062dd47592ec1e4704d43de4c866da6a9c00614b9c59046ce3e7de738f281292302203e419daa01806d5999540805c0705c6076dd7a548bd357801b81da089b272131012102fd2d821fc03cc96b651af392b63d89ff8d328ad9e631732b92dde52cd6ecf88e00000000
{
 "txid": "32b3e8a10e6e01ac05a69695703633fbefd0ea20c22ed3b399266bfc62dff07f",
 "hash": "b3645dd2f06972eef13e5d4eaedb926247972c97f12311ae543243ff20223425",
 "version": 2,
 "size": 191,
 "vsize": 110,
 "weight": 437,
 "locktime": 0,
 "vin": [
   {
     "txid": "bb944dabc9e59934e229d989fd03635d01129a3afab5df9677413dbba6887843",
     "vout": 0,
     "scriptSig": {
       "asm": "",
       "hex": ""
     },
     "txinwitness": [
       "3044022062dd47592ec1e4704d43de4c866da6a9c00614b9c59046ce3e7de738f281292302203e419daa01806d5999540805c0705c6076dd7a548bd357801b81da089b27213101",
       "02fd2d821fc03cc96b651af392b63d89ff8d328ad9e631732b92dde52cd6ecf88e"
     ],
     "sequence": 4294967295
   }
 ],
 "vout": [
   {
     "value": 49.99000000,
     "n": 0,
     "scriptPubKey": {
       "asm": "0 91ec81b14179fa240ce51dadb28530f8c22b20cf",
       "hex": "001491ec81b14179fa240ce51dadb28530f8c22b20cf",
       "reqSigs": 1,
       "type": "witness_v0_keyhash",
       "addresses": [
         "bcrt1qj8kgrv2p08azgr89rkkm9pfslrpzkgx0k6899s"
       ]
     }
   }
 ]
}

# Again use the signed serialized tx
$ bitcoin-cli sendrawtransaction 02000000000101437888a6bb3d417796dfb5fa3a9a12015d6303fd89d929e23499e5c9ab4d94bb0000000000ffffffff01c0aff6290100000016001491ec81b14179fa240ce51dadb28530f8c22b20cf02473044022062dd47592ec1e4704d43de4c866da6a9c00614b9c59046ce3e7de738f281292302203e419daa01806d5999540805c0705c6076dd7a548bd357801b81da089b272131012102fd2d821fc03cc96b651af392b63d89ff8d328ad9e631732b92dde52cd6ecf88e00000000
32b3e8a10e6e01ac05a69695703633fbefd0ea20c22ed3b399266bfc62dff07f

# Generate one block
$ bitcoin-cli generatetoaddress 1 bcrt1qw8js9ept9zc6c7vf2u98des6y4luu70eh23p9g 
[
 "377bf7b9c9d26e3d64b3b5d87fc676872ef94f38be38a279e5967203f687ff75"
]

$ bitcoin-cli listunspent                                                     
[
 {
   "txid": "b06f7e5879292dccfcbecca3be9eb1dcc21b3c83049d87b8bd937142ea39ed2f",
   "vout": 0,
   "address": "bcrt1qw8js9ept9zc6c7vf2u98des6y4luu70eh23p9g",
   "label": "",
   "scriptPubKey": "001471e502e42b28b1ac7989570a76e61a257fce79f9",
   "amount": 50.00000000,
   "confirmations": 101,
   "spendable": true,
   "solvable": true,
   "desc": "wpkh([eed40f16/0'/0'/0']02fd2d821fc03cc96b651af392b63d89ff8d328ad9e631732b92dde52cd6ecf88e)#gf3v6744",
   "safe": true
 },
 {
   "txid": "32b3e8a10e6e01ac05a69695703633fbefd0ea20c22ed3b399266bfc62dff07f",
   "vout": 0,
   "address": "bcrt1qj8kgrv2p08azgr89rkkm9pfslrpzkgx0k6899s",
   "label": "",
   "scriptPubKey": "001491ec81b14179fa240ce51dadb28530f8c22b20cf",
   "amount": 49.99000000,
   "confirmations": 1,
   "spendable": true,
   "solvable": true,
   "desc": "wpkh([eed40f16/0'/0'/1']03d0dffe428dd9c6b6f1ab8620dba11acf507a2c09e6a8d6edf5123cb85499aff0)#jh0umgla",
   "safe": true
 }
]

ah yes that was it :slight_smile: thanks man

btw, does anyone know how to ‘reset’ the regtest/restart blockchain with homebrew on macos. Apparently theres a regtest directory that just need to be deleted but I don’t see it anywhere in /usr/local/opt/bitcoin

You have to remove the data in Bitcoin data directory, not the installation:

https://en.bitcoin.it/wiki/Data_directory

any idea where the directory is in a homebrew scenario?

Is it not the same as for mac?

~/Library/Application Support/Bitcoin/

If not its probably in the standard *NIX dir

~/.bitcoin

Thanx, got it to work on my mac.

Hi

I’m trying to follow the video in the lecture and I’ve selected JSON as the programming language but “txid” and “vout” are not in red as per the video.

I’m not sure what I have done incorrectly?

I’ve attached a screenshot.

Thank you.

You’re probably just using a different color theme. So its not an issue,

1 Like