hyperledger/fabric · error
peer address must be set
Error message
peer address must be set
What it means
NewPeerClientForAddress creates a PeerClient for a given peer address, but refuses to build one when the address string is empty. It is a guard against constructing a client that could never dial. The address must be a non-empty host:port string.
Source
Thrown at internal/peer/common/peerclient.go:40
type PeerClient struct {
*CommonClient
}
// NewPeerClientFromEnv creates an instance of a PeerClient from the global
// Viper instance
func NewPeerClientFromEnv() (*PeerClient, error) {
address, clientConfig, err := configFromEnv("peer")
if err != nil {
return nil, errors.WithMessage(err, "failed to load config for PeerClient")
}
return newPeerClientForClientConfig(address, clientConfig)
}
// NewPeerClientForAddress creates an instance of a PeerClient using the
// provided peer address and, if TLS is enabled, the TLS root cert file
func NewPeerClientForAddress(address, tlsRootCertFile string) (*PeerClient, error) {
if address == "" {
return nil, errors.New("peer address must be set")
}
clientConfig := comm.ClientConfig{}
clientConfig.DialTimeout = viper.GetDuration("peer.client.connTimeout")
if clientConfig.DialTimeout == time.Duration(0) {
clientConfig.DialTimeout = defaultConnTimeout
}
secOpts := comm.SecureOptions{
UseTLS: viper.GetBool("peer.tls.enabled"),
RequireClientCert: viper.GetBool("peer.tls.clientAuthRequired"),
ServerNameOverride: viper.GetString("peer.tls.serverhostoverride"),
}
if secOpts.RequireClientCert {
var err error
secOpts.Key, secOpts.Certificate, err = getClientAuthInfoFromEnv("peer")
if err != nil {View on GitHub (pinned to 2736b63f8f)
Solutions
- Pass the peer address explicitly, e.g. NewPeerClientForAddress("peer0.org1.example.com:7051", tlsRootCertFile)
- Set peer.address in core.yaml or the --peerAddress CLI flag
- Check the code path that produced the empty address (e.g. URL parsing returned empty host) and fix upstream
Example fix
// before
client, err := common.NewPeerClientForAddress("", tlsCert)
// after
client, err := common.NewPeerClientForAddress("peer0.org1.example.com:7051", tlsCert) Defensive patterns
Strategy: validation
Validate before calling
func peerAddressConfigured() error {
addr := viper.GetString("peer.address")
if addr == "" {
return errors.New("peer address must be provided via --peerAddress or peer.address in core.yaml")
}
if _, _, err := net.SplitHostPort(addr); err != nil {
return fmt.Errorf("peer address %q is not host:port: %w", addr, err)
}
return nil
} Try / catch
client, err := common.NewPeerClientForAddress(addr, tlsCert)
if err != nil {
if strings.Contains(err.Error(), "peer address must be set") {
return fmt.Errorf("configure --peerAddress before invoking: %w", err)
}
return err
} Prevention
- Set peer.address in core.yaml as a default
- Always pass --peerAddress on peer CLI commands
- Validate host:port format before constructing clients
When it happens
Trigger: Calling NewPeerClientForAddress("", ...) directly, or newPeerClient resolving an empty peer address because no peer address was configured or passed on the command line.
Common situations: Missing --peerAddress flag on peer CLI commands; peer.address empty in core.yaml; environment variable override not set in container; programmatic use passing empty string when peer lookup failed earlier.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- error receiving from peer deliver service
- tls root cert file must be set
- proposal failed with status: %d - %s
- chaincode install failed: received proposal response with ni
- peer address is not in the format of host:port: %v
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/880be2dd6be68f09.
Report an issue: GitHub.