Create 17_1_blockinfo.go

This commit is contained in:
Shannon Appelcline 2020-09-01 08:54:48 -10:00 committed by GitHub
parent 32709314fc
commit 2812f1fec2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

34
src/17_1_blockinfo.go Normal file
View File

@ -0,0 +1,34 @@
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())
}