mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-07 07:56:31 +00:00
Create 17_1_blockinfo.go
This commit is contained in:
parent
32709314fc
commit
2812f1fec2
34
src/17_1_blockinfo.go
Normal file
34
src/17_1_blockinfo.go
Normal 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())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user