Created
February 22, 2024 22:22
-
-
Save arnabmitra/5220e89d73d56727124ba6a3a263a414 to your computer and use it in GitHub Desktop.
Simple call to regtest to get balances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/btcsuite/btcd/rpcclient" | |
"os" | |
) | |
func main() { | |
// Command-line arguments: address | |
if len(os.Args) < 2 { | |
fmt.Println("Usage: getbalance <address>") | |
return | |
} | |
address := os.Args[1] | |
// Connect to your regtest bitcoind node | |
connCfg := &rpcclient.ConnConfig{ | |
Host: "127.0.0.1:1112", // Adjust port if needed | |
User: "user", | |
Pass: "password", | |
HTTPPostMode: true, // Bitcoin core usually uses HTTP POST | |
DisableTLS: true, // Regtest usually operates without TLS | |
} | |
client, err := rpcclient.New(connCfg, nil) | |
if err != nil { | |
fmt.Println("Error connecting to bitcoind:", err) | |
return | |
} | |
defer client.Shutdown() | |
// Retrieve the balance | |
balance, err := client.GetBalance("*") | |
if err != nil { | |
fmt.Println("Error getting balance:", err) | |
return | |
} | |
// Display the results | |
fmt.Printf("Balance of address %s: %v BTC\n", address, balance) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment