mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-07 07:56:31 +00:00
35 lines
638 B
Go
35 lines
638 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"fmt"
|
|
"github.com/btcsuite/btcd/rpcclient"
|
|
)
|
|
|
|
func main() {
|
|
connCfg := &rpcclient.ConnConfig{
|
|
Host: "localhost:18332",
|
|
User: "StandUp",
|
|
Pass: "6305f1b2dbb3bc5a16cd0f4aac7e1eba",
|
|
HTTPPostMode: true,
|
|
DisableTLS: true,
|
|
}
|
|
client, err := rpcclient.New(connCfg, nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer client.Shutdown()
|
|
|
|
blockCount, err := client.GetBlockCount()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
blockHash, err := client.GetBlockHash(blockCount)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
fmt.Printf("%d\n", blockCount)
|
|
fmt.Printf("%s\n", blockHash.String())
|
|
}
|