OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / btcsuite / btcd / rpcclient / examples / bitcoincorehttp / main.go
1 // Copyright (c) 2014-2017 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
4
5 package main
6
7 import (
8         "log"
9
10         "github.com/btcsuite/btcd/rpcclient"
11 )
12
13 func main() {
14         // Connect to local bitcoin core RPC server using HTTP POST mode.
15         connCfg := &rpcclient.ConnConfig{
16                 Host:         "localhost:8332",
17                 User:         "yourrpcuser",
18                 Pass:         "yourrpcpass",
19                 HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
20                 DisableTLS:   true, // Bitcoin core does not provide TLS by default
21         }
22         // Notice the notification parameter is nil since notifications are
23         // not supported in HTTP POST mode.
24         client, err := rpcclient.New(connCfg, nil)
25         if err != nil {
26                 log.Fatal(err)
27         }
28         defer client.Shutdown()
29
30         // Get the current block count.
31         blockCount, err := client.GetBlockCount()
32         if err != nil {
33                 log.Fatal(err)
34         }
35         log.Printf("Block count: %d", blockCount)
36 }