import "github.com/btcsuite/btcd/chaincfg/chainhash" import "github.com/btcsuite/btcutil" // Create a new Block struct newBlock := btcutil.NewBlock(&wire.MsgBlock{ Header: wire.BlockHeader{ PrevBlock: *chainhash.NewHashFromStr("00000000000000000735a4a51d27d1d5c2c54c81d61dfea204e037d7d6d7dca"), Timestamp: time.Unix(1610299111, 0), Bits: 402930087, Nonce: 0, }, Transactions: []*wire.MsgTx{}, })
import "bytes" import "io" import "github.com/btcsuite/btcutil/binary" // Create a new MsgBlock struct newMsgBlock := &wire.MsgBlock{ Header: wire.BlockHeader{}, Transactions: []*wire.MsgTx{}, } // Serialize the MsgBlock to a byte slice var buf bytes.Buffer if err := newMsgBlock.Serialize(&buf); err != nil { log.Fatal(err) } serialized := buf.Bytes()Both the Block and MsgBlock types are part of the btcsuite/btcutil package library, which provides utility functions for working with Bitcoin data structures.