Creating a Raw Transaction - Discussion

@filip, string escaping is not needed under linux.
Just letting you know.

2019-04-30%2011_01_21-dodikk%40DESKTOP-MJQ2MP4_%20~

1 Like

Great! I’m glad you solved it. I’m not sure how subsystems handle ports. You might have to do some research as to why it can’t bind. Might be a lot of resources in the bitcoin forums as well.

I assume you don’t have another bitcoin instance running on that port? Even in the background. If so you need to stop it. You could also try to changing the port in your bitcoin.conf.

No. I don’t think so.

You might have to do some research as to why it can’t bind. Might be a lot of resources in the bitcoin forums as well.
You could also try to changing the port in your bitcoin.conf.

I’ll try this later. Thanks.

So I’ve managed to sign and send the raw transaction (in Linux subsystem of Win10). as Philip has shown in his video.

dodikk@DESKTOP-MJQ2MP4:~$ bitcoin-cli -regtest sendrawtransaction 02000000010efdea2030d994a4cf5037f53c5cc739499164c9c26bc6b6a981d51f7efbed70000000004847304402200438ece7a4304ea3115bb51e714e2e99f5f3506e9f8240d493ed41f4555aacf802203b1320202791e8ca9f5fda6e0996d6defeb1a19fab3f5e9fdc8e57aeb0b84d6801ffffffff02001110240100000017a914ac67eb8ee455667ce1ccd6bcaf115d0b29f8509687c09ee6050000000017a914994748a8b84b091227c3b68773df3921004e61a18700000000

bca213de3e96254cf0840566ab375c2b1d6640d7bcf045d738c2a444e33f3e26


dodikk@DESKTOP-MJQ2MP4:~$ bitcoin-cli -regtest generate 1
[
  "7293bd3d3f9a175a2e2f03c941659e0680a8b7f42a9ba43976ae4f67e64a36e7"
]



dodikk@DESKTOP-MJQ2MP4:~$ bitcoin-cli -regtest listunspent | grep bca213de3e96254cf0840566ab375c2b1d6640d7bcf045d738c2a444e33f3e26
    "txid": "bca213de3e96254cf0840566ab375c2b1d6640d7bcf045d738c2a444e33f3e26",
    "txid": "bca213de3e96254cf0840566ab375c2b1d6640d7bcf045d738c2a444e33f3e26",
1 Like

After sending a Bitcoin transaction, how can wallet check the confirmation status? and How to check the transaction fee?

Confirmation status is about how many blocks have been mined on top of your block. So you can check that by checking the block height.

I think different wallets use different methods for calculating the fee. You can base it both on the current mempool or on previous blocks. You can read this blog post if you want to get a full picture: https://bitcointechtalk.com/an-introduction-to-bitcoin-core-fee-estimation-27920880ad0

As pointed out by @cata on the other thread, generate has become deprecated in bitcoin 0.18, get one of your addresses or a new one and generate a new block with ./bitcoin-cli -regtest generatetoaddress 1 <your_address>

Thank you for noticing. I’ve added some text about that.

1 Like

Hey, I got this from my last tx
“txid”: “ac6a637be042707117ec8262d32fdacc375d0599b455f5a67680fa9e19d214f8”,
“vout”: 1,

Didn`t you say that vout is always 0?

Thanks

Hey,

Can you please help? I cannot figure out what the error is

I got an error message:
error: Error parsing JSON:{“2NBsVSyyPt3VmJBeJGVHxkHx7L17ebt5qms”: 5,}

Here`s my code:
./bitcoin-cli -regtest createrawtransaction ‘[{“txid”: “a5c882ee895b4983b7fef6f6a91d214965df124956269d568f976b5854c7c1f7”,“vout”: 0}]’ ‘{“2NBsVSyyPt3VmJBeJGVHxkHx7L17ebt5qms”: 5,}’

No, it’s not always zero. vout is the number outputs in that tx.

1 Like

You should not have the comma after the five. That indicates something is coming after it, but in your case. The 5 is the end of the object. So you should just have nothing

1 Like

Yes! That worked, thanks a lot!

When I made the locking script I got a much shorter "asm"code than you?

“vin”: [
{
“txid”: “a5c882ee895b4983b7fef6f6a91d214965df124956269d568f976b5854c7c1f7”,
“vout”: 0,
“scriptSig”: {
“asm”: “0014fb660c11feb2e6a4ba4ace215599ac7dbe984e4a”,

Also when I made the unlocking script I did not get the OP_CHECKSIG but I got OP_EQUAL instead. Any idea why?

“vout”: [
{
“value”: 10.00000000,
“n”: 0,
“scriptPubKey”: {
“asm”: “OP_HASH160 cc4e24f52c784fffb09b315ed48702cbcbc25069 OP_EQUAL”,

First of all you have the two mixed up. The first one is your unlocking script and the second part is your locking script.

If you look at my locking script (in part 2), you will see I also have OP_EQUAL.

But your unlocking script looks a little bit weird, did you sign it? Can you send your entire signed transaction here. Please send it using the code format here in the forum.

First I
listed my unspent transactions and picked this one:

{

"txid":

“a5c882ee895b4983b7fef6f6a91d214965df124956269d568f976b5854c7c1f7”,

"vout": 0,

"address":

“2MuZFcnDYT5AVnvMkXQjZiiBLqxPdtDFSzK”,

"label": "",

"redeemScript":

“0014fb660c11feb2e6a4ba4ace215599ac7dbe984e4a”,

"scriptPubKey":

“a91419591952119e85d4186b24496bbb1c842edffbc587”,

"amount": 25.00000000,

"confirmations": 101,

"spendable": true,

"solvable": true,

"desc":

“sh(wpkh([ecf267e4/0’/0’/2’]0344dd2eb0e908cd0624e18281a2aeccde1de8a20b4e06279a78657c31708ca9d9))#gasgq3jv”,

"safe": true

},

Then I used
the command getnewaddress:

2NCKJydykRGfCvG7bNuJtAnQ1emGSEhkYEr

Then I made
the string in Atom and input txid and new wallet address into string:

‘[{“txid”:
“a5c882ee895b4983b7fef6f6a91d214965df124956269d568f976b5854c7c1f7”,“vout”:
0}]’ ‘{“2NCKJydykRGfCvG7bNuJtAnQ1emGSEhkYEr”: 10}’

Then I:
createrawtransaction using the string above and got:

0200000001f7c1c754586b978f569d26564912df6549211da9f6f6feb783495b89ee82c8a50000000000ffffffff0100ca9a3b0000000017a914d13037de674c958f20a19468264bd462cb0614ac8700000000

I then used
the signtransactionwithwallet and got:

02000000000101f7c1c754586b978f569d26564912df6549211da9f6f6feb783495b89ee82c8a50000000017160014fb660c11feb2e6a4ba4ace215599ac7dbe984e4affffffff0100ca9a3b0000000017a914d13037de674c958f20a19468264bd462cb0614ac870247304402200cc9f29abcca9eb3d4c1f86284944727e5e6cce698cb7a40afbec42994016dc302203e99b78da69bbd07f1dcd36f891f331d314c453986f69d33deafcf37116c545b01210344dd2eb0e908cd0624e18281a2aeccde1de8a20b4e06279a78657c31708ca9d900000000

I then
decoded the transaction after signing it:

PS
F:\Bitcoin Core\Bitcoin\daemon> ./bitcoin-cli -regtest decoderawtransaction
02000000000101f7c1c754586b978f569d26564912df6549211da9f6f6feb783495b89ee82c8a50000000017160014fb660c11feb2e6a4ba4ace215599ac7dbe984e4affffffff0100ca9a3b0000000017a914d13037de674c958f20a19468264bd462cb0614ac870247304402200cc9f29abcca9eb3d4c1f86284944727e5e6cce698cb7a40afbec42994016dc302203e99b78da69bbd07f1dcd36f891f331d314c453986f69d33deafcf37116c545b01210344dd2eb0e908cd0624e18281a2aeccde1de8a20b4e06279a78657c31708ca9d900000000

{

“txid”:
“d04b336a2963ab3d5aced77edb6a967af8eae3d8f402dcee2b2d5e3537313ed5”,

“hash”: “941c5cc29bf1da825f1646413e5d8d86c8f47a1bd9b7d77a0ef96952a4f82c8e”,

“version”: 2,

“size”: 215,

“vsize”: 134,

“weight”: 533,

“locktime”: 0,

“vin”: [

{

  "txid":

“a5c882ee895b4983b7fef6f6a91d214965df124956269d568f976b5854c7c1f7”,

  "vout": 0,

  "scriptSig": {

    "asm":

“0014fb660c11feb2e6a4ba4ace215599ac7dbe984e4a”,

    "hex":

“160014fb660c11feb2e6a4ba4ace215599ac7dbe984e4a”

  },

  "txinwitness": [

“304402200cc9f29abcca9eb3d4c1f86284944727e5e6cce698cb7a40afbec42994016dc302203e99b78da69bbd07f1dcd36f891f331d314c453986f69d33deafcf37116c545b01”,

“0344dd2eb0e908cd0624e18281a2aeccde1de8a20b4e06279a78657c31708ca9d9”

  ],

  "sequence": 4294967295

}

],

“vout”: [

{

  "value": 10.00000000,

  "n": 0,

  "scriptPubKey": {

    "asm": "OP_HASH160

d13037de674c958f20a19468264bd462cb0614ac OP_EQUAL",

    "hex":

“a914d13037de674c958f20a19468264bd462cb0614ac87”,

    "reqSigs": 1,

    "type": "scripthash",

    "addresses": [

“2NCKJydykRGfCvG7bNuJtAnQ1emGSEhkYEr”

    ]

  }

}

]

}

Here`s
where your vin scriptsig “asm” is much longer than my and without the [ALL] at
the end.

My thougth
is that this is my unlocking script since it`s the vin “asm”, is it not?

“vin”: [

{

  "txid":

“a5c882ee895b4983b7fef6f6a91d214965df124956269d568f976b5854c7c1f7”,

  "vout": 0,

  "scriptSig": {

    "asm":

“0014fb660c11feb2e6a4ba4ace215599ac7dbe984e4a”,

“vout”:
[

{

  "value": 10.00000000,

  "n": 0,

  "scriptPubKey": {

    "asm": "OP_HASH160

d13037de674c958f20a19468264bd462cb0614ac OP_EQUAL",

Then I put
the original txid into the gettxout:

PS
F:\Bitcoin Core\Bitcoin\daemon> ./bitcoin-cli -regtest gettxout
“a5c882ee895b4983b7fef6f6a91d214965df124956269d568f976b5854c7c1f7”, 0

{

“bestblock”:
“2d03fe757d5dd3670b044e83702c4a9bc526993e560aa3808521e4e085f16bd9”,

“confirmations”: 101,

“value”: 25.00000000,

“scriptPubKey”: {

"asm": "OP_HASH160

19591952119e85d4186b24496bbb1c842edffbc5 OP_EQUAL",

"hex":

“a91419591952119e85d4186b24496bbb1c842edffbc587”,

"reqSigs": 1,

"type": "scripthash",

"addresses": [

“2MuZFcnDYT5AVnvMkXQjZiiBLqxPdtDFSzK”

]

},

“coinbase”: true

I put the
the locking script below from the gettxout “asm” command, did I misunderstand
this? This does not look right, but I can not tell why

UNLOCKING: 0014fb660c11feb2e6a4ba4ace215599ac7dbe984e4a

LOCKING: OP_HASH160
19591952119e85d4186b24496bbb1c842edffbc5 OP_EQUAL

Ok, thanks. Now it makes more sense. Your unlocking script is different because yours is a segwit transaction. So your signature is in the witness field, as you can see in your signed transaction. So that’s why your unlocking script is shorter.

It seems that there has been a new release of bitcoind (version 0.18) that changes how it handles witness scripts. But I’m confused why your coinbase transaction gave you 25 bitcoin instead of 50, I don’t understand why that would happen.

But there is nothing wrong with your transaction. Everything looks fine.

Hi Filip, i have some questions. My result is different compared to the videopart 3:
I have my signature in txinwitness:
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest signrawtransactionwithwallet 020000000134f6d8abf728844632d50fe0bf42db6382bb8eaeb824a7e2965190e332cd58d00000000000ffffffff01001110240100000017a914fa8c9783a0c55109c991f2ec24b63c1bd9602b648700000000
{
“hex”: “0200000000010134f6d8abf728844632d50fe0bf42db6382bb8eaeb824a7e2965190e332cd58d00000000017160014fc980f16db921697c0bfe8c3711fd27c7a9f26c1ffffffff01001110240100000017a914fa8c9783a0c55109c991f2ec24b63c1bd9602b64870247304402203125f4b36fab4033b91e2ce2009018cd235b9c2f3f3ea8437817e702f167206d02202198d3dbd34ba8e23b1707a9789faee8c7d9f1ffdbd008ea55fd8ac9cd1ffdc1012103342631815b73e73cb5696d32db5be46248f3343543a13a1b28b6c642a7a6b8e300000000”,
“complete”: true
}
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest decoderawtransaction 0200000000010134f6d8abf728844632d50fe0bf42db6382bb8eaeb824a7e2965190e332cd58d00000000017160014fc980f16db921697c0bfe8c3711fd27c7a9f26c1ffffffff01001110240100000017a914fa8c9783a0c55109c991f2ec24b63c1bd9602b64870247304402203125f4b36fab4033b91e2ce2009018cd235b9c2f3f3ea8437817e702f167206d02202198d3dbd34ba8e23b1707a9789faee8c7d9f1ffdbd008ea55fd8ac9cd1ffdc1012103342631815b73e73cb5696d32db5be46248f3343543a13a1b28b6c642a7a6b8e300000000
{
“txid”: “bbf9e83f342a1a61a99ccd804b2b614dfe9b8364976920d26252f6dbb6891e91”,
“hash”: “7687acce64a2941defc4042c0c5343517bb4b1bd80a5f8011c0a611563bc92e1”,
“version”: 2,
“size”: 215,
“vsize”: 134,
“weight”: 533,
“locktime”: 0,
“vin”: [
{
“txid”: “d058cd32e3905196e2a724b8ae8ebb8263db42bfe00fd532468428f7abd8f634”,
“vout”: 0,
“scriptSig”: {
“asm”: “0014fc980f16db921697c0bfe8c3711fd27c7a9f26c1”,
“hex”: “160014fc980f16db921697c0bfe8c3711fd27c7a9f26c1”
},
“txinwitness”: [
“304402203125f4b36fab4033b91e2ce2009018cd235b9c2f3f3ea8437817e702f167206d02202198d3dbd34ba8e23b1707a9789faee8c7d9f1ffdbd008ea55fd8ac9cd1ffdc101”,
“03342631815b73e73cb5696d32db5be46248f3343543a13a1b28b6c642a7a6b8e3”
],
“sequence”: 4294967295
}
],
“vout”: [
{
“value”: 49.00000000,
“n”: 0,
“scriptPubKey”: {
“asm”: “OP_HASH160 fa8c9783a0c55109c991f2ec24b63c1bd9602b64 OP_EQUAL”,
“hex”: “a914fa8c9783a0c55109c991f2ec24b63c1bd9602b6487”,
“reqSigs”: 1,
“type”: “scripthash”,
“addresses”: [
“2NG61LjZo9s23ZNtpxoBzDBQGVJYvhZKvwi”
]
}
}
]
}

Hi Filip, in video part 4 you stated that gettxout should give an OP_CHECKSIG. This is my result:
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest listunspent
[
{
“txid”: “d058cd32e3905196e2a724b8ae8ebb8263db42bfe00fd532468428f7abd8f634”,
“vout”: 0,
“address”: “2N72N9ko7LjDaizKkiL2XJd3fsGry67Xf5r”,
“label”: “”,
“redeemScript”: “0014fc980f16db921697c0bfe8c3711fd27c7a9f26c1”,
“scriptPubKey”: “a91497232af8b0cb2d7769981c1cbc123ef1c7b86e9787”,
“amount”: 50.00000000,
“confirmations”: 106,
“spendable”: true,
“solvable”: true,
“desc”: “sh(wpkh([3cb8d47d/0’/0’/3’]03342631815b73e73cb5696d32db5be46248f3343543a13a1b28b6c642a7a6b8e3))#r47dm9v5”,
“safe”: true
},
{
“txid”: “fbad73ef559fb4363a15e15a9dbbd605f24f6dee82268392b1fa9e74af38c380”,
“vout”: 0,
“address”: “2N59pJXpn8jdtaoUAKXoVP69y2TXigmXqZZ”,
“redeemScript”: “00148a07bb7697e778a7369a0b2480c4dd5ae33762ac”,
“scriptPubKey”: “a914829ba8756e854e89d181a7bc223a487900a0a13687”,
“amount”: 39.99987620,
“confirmations”: 1,
“spendable”: true,
“solvable”: true,
“desc”: “sh(wpkh([3cb8d47d/0’/1’/0’]024228b1e83ad58472ed7383e5bb4c97332114185f84e61fdb778b79ef25867f93))#zr0d0ry0”,
“safe”: true
},
{
“txid”: “fbad73ef559fb4363a15e15a9dbbd605f24f6dee82268392b1fa9e74af38c380”,
“vout”: 1,
“address”: “2N5hQLHz8zGe7UZaS3uHiQ7hxotTUePq7jC”,
“label”: “”,
“redeemScript”: “0014e163ea747ce8bc6708cc50948ab60c265384e001”,
“scriptPubKey”: “a9148894f5c12bf1e7839aa7af888c566c8829fb19e887”,
“amount”: 260.00000000,
“confirmations”: 1,
“spendable”: true,
“solvable”: true,
“desc”: “sh(wpkh([3cb8d47d/0’/0’/4’]0286a3360cb4333c3c06d3589467dbdd2928ee3dc4f0dc5ff8fbce4c0538a5ad75))#fxfu6jug”,
“safe”: true
},
{
“txid”: “6c98b0cc57eb389b49ca27f19020be2782eae2e92fdd7182d1a03f28d782bbbf”,
“vout”: 0,
“address”: “2N72N9ko7LjDaizKkiL2XJd3fsGry67Xf5r”,
“label”: “”,
“redeemScript”: “0014fc980f16db921697c0bfe8c3711fd27c7a9f26c1”,
“scriptPubKey”: “a91497232af8b0cb2d7769981c1cbc123ef1c7b86e9787”,
“amount”: 50.00000000,
“confirmations”: 101,
“spendable”: true,
“solvable”: true,
“desc”: “sh(wpkh([3cb8d47d/0’/0’/3’]03342631815b73e73cb5696d32db5be46248f3343543a13a1b28b6c642a7a6b8e3))#r47dm9v5”,
“safe”: true
}
]
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest gettxout “d058cd32e3905196e2a724b8ae8ebb8263db42bfe00fd532468428f7abd8f634”, 0
{
“bestblock”: “649f43d2179763053534d1271115f83ad5ff0932a3d3473b29ab7f28046f0a59”,
“confirmations”: 106,
“value”: 50.00000000,
“scriptPubKey”: {
“asm”: “OP_HASH160 97232af8b0cb2d7769981c1cbc123ef1c7b86e97 OP_EQUAL”,
“hex”: “a91497232af8b0cb2d7769981c1cbc123ef1c7b86e9787”,
“reqSigs”: 1,
“type”: “scripthash”,
“addresses”: [
“2N72N9ko7LjDaizKkiL2XJd3fsGry67Xf5r”
]
},
“coinbase”: true
}

Why do i get OP_EQUAL?

To answer your first question, there seems to have been an update to bitcoind so it now creates segwit transactions by default. That’s why your signature is in witness. Not a problem, just looks different.

The answer to your second question is also very similar to the first answer. Seems like there has been an update so that the standard tx’s now are P2SH tx’s. So it’s a different type of locking script. Also nothing that is wrong on your part. Just an update in the software :slight_smile:

1 Like