import "github.com/conformal/btcutil" // create a new empty transaction tx := btcutil.NewTx() // add an input to the transaction inputHash := btcutil.NewHashFromStr("8f7fca9c8fae177f685985c5e8b06cf55c973bf6b87438604f9e82a19d7897d5") prevOut := btcutil.NewOutPoint(inputHash, 0) scriptSig := []byte{0x01, 0x02, 0x03} txIn := btcutil.NewTxInput(prevOut, scriptSig, 0) tx.AddTxIn(txIn) // add an output to the transaction pkScript := []byte{0x76, 0xA9, 0x14, 0x2A, 0xF3, 0x9E, 0x2D, 0xB2, 0x39, 0x8A, 0xEA, 0x45, 0xE1, 0x57, 0x77, 0x0A, 0xA6, 0xB4, 0x48, 0x8D, 0x36, 0x88, 0xAC} txOut := btcutil.NewTxOut(1000, pkScript) tx.AddTxOut(txOut)
import "github.com/conformal/btcutil" // deserialize a raw transaction txBytes := []byte{0x01, 0x00, 0x00, 0x00, 0x01, 0x6d, 0xbd, 0xdb, 0x08, 0x5b, 0x1d, 0x8a, 0xf7, 0x51, 0x84, 0xf0, 0xbc, 0x01, 0xfa, 0xd5, 0x8d, 0x12, 0x66, 0xe9, 0xb6, 0x49, 0x3b, 0x61, 0x62, 0xa3, 0x22, 0x48, 0x8a, 0xac, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0x67, 0x6a, 0x7a, 0x50, 0x30, 0x2b, 0x91, 0x99, 0xb1, 0x62, 0x81, 0x2b, 0x55, 0x32, 0x36, 0x8a, 0xed, 0x4d, 0xb6, 0x8e, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xbd, 0x46, 0xad, 0x7d, 0xfc, 0x6f, 0xbd, 0xc5, 0x6f, 0x79, 0xea, 0x60, 0xf2, 0x70, 0x1b, 0x23, 0xb9, 0x18, 0x72, 0x9f, 0x13, 0x87, 0xac} tx, err := btcutil.NewTxFromBytes(txBytes) if err != nil { log.Fatal(err) }This example shows how to deserialize a raw transaction byte string into a Tx struct using "NewTxFromBytes".