1 package main
2 3 import (
4 "log"
5 6 "github.com/p9c/p9/pkg/qu"
7 8 "github.com/p9c/p9/pkg/rpcclient"
9 )
10 11 func main() {
12 // Connect to local bitcoin core RPC server using HTTP POST mode.
13 connCfg := &rpcclient.ConnConfig{
14 Host: "localhost:11046",
15 User: "yourrpcuser",
16 Pass: "yourrpcpass",
17 HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
18 TLS: false, // Bitcoin core does not provide TLS by default
19 }
20 // Notice the notification parameter is nil since notifications are not supported in HTTP POST mode.
21 client, e := rpcclient.New(connCfg, nil, qu.T())
22 if e != nil {
23 F.Ln(e)
24 }
25 defer client.Shutdown()
26 // Get the current block count.
27 blockCount, e := client.GetBlockCount()
28 if e != nil {
29 F.Ln(e)
30 }
31 log.Printf("Block count: %d", blockCount)
32 }
33