0

hex: 010000000001026a8da33916366b884349772dc022a39c4cf8d60acc45fd2527a71e5c80cc6da2000000000000000000208a35c4425160d006ed968606485258a1ecca80550ea48def5d44511bab553200000000000000000002e847791400000000160014885f1f476949438e34d3928fcff3449c339f934dc8633b0300000000160014618736c1f42c5029a5887a5ebac292720a4ccd1802483045022100f3d721d184ad19e50ca085fedb0c2654b1c5bd3cedb4b5f1d502ca7f21df125402204d87cda1511ebc1d943b0ee223aa2ade62410c51028d04ffabb3dfd7c1120273012102826930ee848903793b57d2e253284dfa0df86de1103bace30b84ab619e663fb402463043021f718f2adabc9214c196942861bfe93c8e96dd3517c6d4988898a901485ed0c1022007fee4bfd89d6d1f936932c3dd37fcad44cdcd6ec3ad9daebc2b8d8d7da1d5e1012102826930ee848903793b57d2e253284dfa0df86de1103bace30b84ab619e663fb400000000

https://live.blockcypher.com/btc/decodetx/

This site decodes it fine but when I use decoder in golang or python either from bytes or a hex string it outputs garbage, is there something I am missing?

3
  • The hex data you posted is a perfectly cromulent SegWit transaction (this one). I can decode your hex data in go without any obvious problem. Maybe you can post the decoder you are using, full details of how you are using it and full error messages it produces Nov 27, 2022 at 21:32
  • thanks for the reply just like that str :="hex posted", hex.DecodeString(str). dst := make([]byte, hex.DecodedLen(len([]byte(str)))) n, err := hex.Decode(dst, []byte(str))` Nov 27, 2022 at 21:41
  • In Go that just converts hex to binary. You need to also subsequently invoke methods from a proper blockchain parsing libary. Nov 27, 2022 at 21:46

1 Answer 1

0

You must use a library written to parse Blockchain data.

Here's my own example. My library is unpublished, pick a different one from search results

package main

import (
    "encoding/hex"
    "fmt"
    "os"
)

// Read transaction data in hex from a file, parse & print it
func txFromFile(fileName string) {
    txHex, err := os.ReadFile(fileName)
    if err != nil { panic(err) }
    fmt.Println(string(txHex))

    b, err := hex.DecodeString(string(txHex))
    if err != nil { panic(err) }

    tx := parseTx(NewMyBuffer(b), 1)

    // Arbitrary print to show we parsed to a struct
    fmt.Printf("\nThe first output is worth %d Satoshi\n",
        tx.Outputs[0].Value)

    // tx is a Stringer (has String() method)
    fmt.Println(tx)

}

Example use

C> blockchain -txfile tx.hex
010000000001026a8da33916366b884349772dc022a39c4cf8d60acc45fd2527a71e5c80cc6da2000000000000000000208a35c4425160d006ed968606485258a1ecca80550ea48def5d44511bab553200000000000000000002e847791400000000160014885f1f476949438e34d3928fcff3449c339f934dc8633b0300000000160014618736c1f42c5029a5887a5ebac292720a4ccd1802483045022100f3d721d184ad19e50ca085fedb0c2654b1c5bd3cedb4b5f1d502ca7f21df125402204d87cda1511ebc1d943b0ee223aa2ade62410c51028d04ffabb3dfd7c1120273012102826930ee848903793b57d2e253284dfa0df86de1103bace30b84ab619e663fb402463043021f718f2adabc9214c196942861bfe93c8e96dd3517c6d4988898a901485ed0c1022007fee4bfd89d6d1f936932c3dd37fcad44cdcd6ec3ad9daebc2b8d8d7da1d5e1012102826930ee848903793b57d2e253284dfa0df86de1103bace30b84ab619e663fb400000000

The first output is worth 343492584 Satoshi

  Version:................01000000 (1)
  Type:...................0001 (Segwit)
  Inputs:.................02 (2)
  Input:1
    Previous Transaction:.A26DCC805C1EA72725FD45CC0AD6F84C9CA322C02D774943886B361639A38D6A
    Previous Output Index:0000 (0)
    Script Length:........00 (0)
    Unlocking Script:.....
    Sequence:.............00000000
  Input:2
    Previous Transaction:.3255AB1B51445DEF8DA40E5580CAECA1585248068696ED06D0605142C4358A20
    Previous Output Index:0000 (0)
    Script Length:........00 (0)
    Unlocking Script:.....
    Sequence:.............00000000
  Outputs:................02 (2)
  Output 1
    Value:................E847791400000000 (343492584)
    Script Length:........16 (22)
    Locking Script:.......0014885F1F476949438E34D3928FCFF3449C339F934D
  Output 2
    Value:................C8633B0300000000 (54223816)
    Script Length:........16 (22)
    Locking Script:.......0014618736C1F42C5029A5887A5EBAC292720A4CCD18
  Witness 1
    Item Count:...........02 (2)
    Item 1
      Length:.............48 (72)
      Data:...............3045022100F3D721D184AD19E50CA085FEDB0C2654B1C5BD3CEDB4B5F1D502CA
                          7F21DF125402204D87CDA1511EBC1D943B0EE223AA2ADE62410C51028D04FFAB
                          B3DFD7C112027301
    Item 2
      Length:.............21 (33)
      Data:...............02826930EE848903793B57D2E253284DFA0DF86DE1103BACE30B84AB619E663F
                          B4
  Witness 2
    Item Count:...........02 (2)
    Item 1
      Length:.............46 (70)
      Data:...............3043021F718F2ADABC9214C196942861BFE93C8E96DD3517C6D4988898A90148
                          5ED0C1022007FEE4BFD89D6D1F936932C3DD37FCAD44CDCD6EC3AD9DAEBC2B8D
                          8D7DA1D5E101
    Item 2
      Length:.............21 (33)
      Data:...............02826930EE848903793B57D2E253284DFA0DF86DE1103BACE30B84AB619E663F
                          B4
  LockTime:...............00000000 (0)
  (Calculated hash is 2C1DEA91142889092E41F0617250F83E0601E87290FAF0676F813F0F55063270)

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.