Author

Topic: How to get txid from desearialized payto hex (Read 148 times)

newbie
Activity: 4
Merit: 0
Thank you!
legendary
Activity: 3472
Merit: 10611
sorry that is my bad. i am still forget about SegWit most of the times since it is new!

Transaction ID for legacy transactions (without SegWit) requires you to sign the transaction then double SHA the whole transaction to get the TX ID.
but in SegWit you need everything apart from the witness part (which is where your signature is located) to get the TX ID. so basically you do the double SHA on [nVersion][txins][txouts][nLockTime] which fixes the malleability problem too.
https://bitcoin.stackexchange.com/questions/62044/how-to-compute-segwit-txid
newbie
Activity: 4
Merit: 0
It looks like with an unsigned segwit transaction electrum is designed to show the txid

https://github.com/spesmilo/electrum/issues/2904
newbie
Activity: 4
Merit: 0
pooya87 thanks but as I said the electrum GUI (version 3.1.3) does display a transaction ID  Huh

https://imgur.com/a/Y9pCX8h

and you can see it isn't signed.  I thought that an unsigned transaction couldn't have an id but could this because of the segregated witness? 
legendary
Activity: 3472
Merit: 10611
i am not sure what you are trying to do here, but in order to get the transaction ID of a transaction, you just perform SHA256 hashing on it twice. if you have it in decentralized form (the indented JSON looking thing down) you should first stick all those parts together and make the raw hex formal and then do the hashing on it.

if your transaction isn't signed then doing all that is moot because there is no transaction ID for an unsigned transaction yet.
newbie
Activity: 4
Merit: 0
I can see in the GUI that with a testnet segwit multisig (2 of 3) wallet if I send coins Electrum fills in the txid (6affef0a464ab6f9ca0db27216e5b85f4d26a907f2fe9e209cd565584f5cc30b).

If I export the hex
Code:
01000000000101900eadf495c92f148e74fbdb8651c2f6aae903ca98eea005dd176a7b6154d9bb0000000000fdffffff02e8030000000000001976a91453c1d05822e2658fd2e1ce0c88184fd3234b081688ac784d080000000000220020fe3771f4cba56661930763348e73c85b9fe07111a0fef1a4b907ef92453df4c5feffffffff7078080000000000050001ff01ff01fffd0201524c53ff0257548301d9a24f3c8000000128d96fca507ee0abdd7dbb89588f91587199c4b314f7e7c5926c96f55f77715402cf0805a347294c76541850c0bcb5a2b5f8e1c5399344ec6526e4d274f2d224ec000000004c53ff0257548301361ca322800000011e406db645e1e3d11ada4129af80acbca3054b444759ad6d05263eafc7f3a641020110e41e681dc08a02d34f2797eb1d60a7dcffdca6196946eb0594cfc98b7c1e000000004c53ff0257548301c3e4a36e80000001ed6125c56dcb8b8d549da5fdd76392b43eb9c62d705627d24fc3ac4c4c811036035e17384ec7f8247c838ace4c06b23e2094920c469937a568b97020e2f05ec2b00000000053ae0d201400

and deserialize it I get something like

Code:
{
    "inputs": [
        {
            "address": "bc1qctnmckkujaztrwdw7n46j9y0rnrqg4mnt68c7tfgf74ja650wytqnam9tg",
            "num_sig": 2,
            "prevout_hash": "bbd954617b6a17dd05a0ee98ca03e9aaf6c25186dbfb748e142fc995f4ad0e90",
            "prevout_n": 0,
            "pubkeys": [
                "ff0257548301d9a24f3c8000000128d96fca507ee0abdd7dbb89588f91587199c4b314f7e7c5926c96f55f77715402cf0805a347294c76541850c0bcb5a2b5f8e1c5399344ec6526e4d274f2d224ec00000000",
                "ff0257548301361ca322800000011e406db645e1e3d11ada4129af80acbca3054b444759ad6d05263eafc7f3a641020110e41e681dc08a02d34f2797eb1d60a7dcffdca6196946eb0594cfc98b7c1e00000000",
                "ff0257548301c3e4a36e80000001ed6125c56dcb8b8d549da5fdd76392b43eb9c62d705627d24fc3ac4c4c811036035e17384ec7f8247c838ace4c06b23e2094920c469937a568b97020e2f05ec2b000000000"
            ],
            "scriptSig": "",
            "sequence": 4294967293,
            "signatures": [
                null,
                null,
                null
            ],
            "type": "p2wsh",
            "value": 555120,
            "witness": "050001ff01ff01fffd0201524c53ff0257548301d9a24f3c8000000128d96fca507ee0abdd7dbb89588f91587199c4b314f7e7c5926c96f55f77715402cf0805a347294c76541850c0bcb5a2b5f8e1c5399344ec6526e4d274f2d224ec000000004c53ff0257548301361ca322800000011e406db645e1e3d11ada4129af80acbca3054b444759ad6d05263eafc7f3a641020110e41e681dc08a02d34f2797eb1d60a7dcffdca6196946eb0594cfc98b7c1e000000004c53ff0257548301c3e4a36e80000001ed6125c56dcb8b8d549da5fdd76392b43eb9c62d705627d24fc3ac4c4c811036035e17384ec7f8247c838ace4c06b23e2094920c469937a568b97020e2f05ec2b00000000053ae",
            "witnessScript": "524c53ff0257548301d9a24f3c8000000128d96fca507ee0abdd7dbb89588f91587199c4b314f7e7c5926c96f55f77715402cf0805a347294c76541850c0bcb5a2b5f8e1c5399344ec6526e4d274f2d224ec000000004c53ff0257548301361ca322800000011e406db645e1e3d11ada4129af80acbca3054b444759ad6d05263eafc7f3a641020110e41e681dc08a02d34f2797eb1d60a7dcffdca6196946eb0594cfc98b7c1e000000004c53ff0257548301c3e4a36e80000001ed6125c56dcb8b8d549da5fdd76392b43eb9c62d705627d24fc3ac4c4c811036035e17384ec7f8247c838ace4c06b23e2094920c469937a568b97020e2f05ec2b00000000053ae",
            "x_pubkeys": [
                "ff0257548301d9a24f3c8000000128d96fca507ee0abdd7dbb89588f91587199c4b314f7e7c5926c96f55f77715402cf0805a347294c76541850c0bcb5a2b5f8e1c5399344ec6526e4d274f2d224ec00000000",
                "ff0257548301361ca322800000011e406db645e1e3d11ada4129af80acbca3054b444759ad6d05263eafc7f3a641020110e41e681dc08a02d34f2797eb1d60a7dcffdca6196946eb0594cfc98b7c1e00000000",
                "ff0257548301c3e4a36e80000001ed6125c56dcb8b8d549da5fdd76392b43eb9c62d705627d24fc3ac4c4c811036035e17384ec7f8247c838ace4c06b23e2094920c469937a568b97020e2f05ec2b000000000"
            ]
        }
    ],
    "lockTime": 1318925,
    "outputs": [
        {
            "address": "18dsGLx3Gk9oQakYkDUALkS5bEYjHjQz12",
            "prevout_n": 0,
            "scriptPubKey": "76a91453c1d05822e2658fd2e1ce0c88184fd3234b081688ac",
            "type": 0,
            "value": 1000
        },
        {
            "address": "bc1qlcmhraxt54nxryc8vv6guu7gtw07qug35rl0rf9eqlhey3fa7nzswr9v9p",
            "prevout_n": 1,
            "scriptPubKey": "0020fe3771f4cba56661930763348e73c85b9fe07111a0fef1a4b907ef92453df4c5",
            "type": 0,
            "value": 544120
        }
    ],
    "version": 1
}

But I can't work out how to get the txid from either the hex (which isn't valid a transaction hex) or from the deserialized transaction.

I've tried using https://github.com/chainside/btcnodejs but surely there is an easier way.
Jump to: