Categorygithub.com/shuber/go-bitcoin
modulepackage
0.0.0-20241011130404-63c843ee0510
Repository: https://github.com/shuber/go-bitcoin.git
Documentation: pkg.go.dev

# README

go-bitcoin

Go wrapper for bitcoin RPC

RPC services

Start by creating a connection to a bitcoin node

  b, err := New("rcp host", rpc port, "rpc username", "rpc password", false)
  if err != nil {
    log.Fatal(err)
  }

Then make a call to bitcoin

  res, err := b.GetBlockchainInfo()
  if err != nil {
    log.Fatal(err)
  }
  fmt.Printf("%#v\n", res)

Available calls are:

GetConnectionCount()
GetBlockchainInfo()
GetNetworkInfo()
GetNetTotals()
GetMiningInfo()
Uptime()
GetMempoolInfo()
GetRawMempool(details bool)
GetChainTxStats(blockcount int)
ValidateAddress(address string)
GetHelp()
GetBestBlockHash()
GetBlockHash(blockHeight int)
SendRawTransaction(hex string)
GetBlock(blockHash string)
GetBlockOverview(blockHash string)
GetBlockHex(blockHash string)
GetRawTransaction(txID string)
GetRawTransactionHex(txID string)
GetBlockTemplate(includeSegwit bool)
GetMiningCandidate()
SubmitBlock(hexData string)
SubmitMiningSolution(candidateID string, nonce uint32,
                     coinbase string, time uint32, version uint32)
GetDifficulty()
DecodeRawTransaction(txHex string)
GetTxOut(txHex string, vout int, includeMempool bool)
ListUnspent(addresses []string)

ZMQ

It is also possible to subscribe to a bitcoin node and be notified about new transactions and new blocks via the node's ZMQ interface.

First, create a ZMQ instance:

  zmq := bitcoin.NewZMQ("localhost", 28332)

Then create a buffered or unbuffered channel of strings and a goroutine to consume the channel:

	ch := make(chan string)

	go func() {
		for c := range ch {
			log.Println(c)
		}
	}()

Finally, subscribe to "hashblock" or "hashtx" topics passing in your channel:

	err := zmq.Subscribe("hashblock", ch)
	if err != nil {
		log.Fatalln(err)
	}

# Packages

No description provided by the author

# Functions

New return a new bitcoind.
NewBitIndexClient returns a new bitIndex client for the given url.
No description provided by the author
No description provided by the author
No description provided by the author
TransactionFromBytes takes a slice of bytes and constructs a Transaction object.
TransactionFromHex takes a hex string and constructs a Transaction object.
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

Address comment.
No description provided by the author
No description provided by the author
BbBlock struct.
No description provided by the author
No description provided by the author
A Bitcoind represents a Bitcoind client.
BitIndex comment.
Block struct.
Block2 struct.
BlockchainInfo comment.
BlockHeader comment.
BlockHeaderAndCoinbase comment.
BlockOverview struct.
BlockPage to store links.
No description provided by the author
BlockTemplate comment.
BlockTxid comment.
BytesData struct.
ChainTXStats struct.
No description provided by the author
Error comment.
GetInfo comment.
LocalAddress comment.
No description provided by the author
MempoolInfo comment.
MiningCandidate comment.
MiningInfo comment.
NetTotals comment.
Network comment.
NetworkInfo comment.
OpReturn comment.
Peer struct.
RawTransaction comment.
ScriptPubKey Comment.
A ScriptSig represents a scriptsig.
No description provided by the author
SignRawTransactionResponse struct.
Tag.
No description provided by the author
Transaction comment.
No description provided by the author
No description provided by the author
UnspentTransaction type.
Utxo bitindex comment.
UtxoResponse comment.
Vin represent an IN value.
Vout represent an OUT value.
ZMQ struct.

# Interfaces

No description provided by the author

# Type aliases

ChainTips comment.
No description provided by the author
PeerInfo comment.
RawMemPool comment.