"no addresses" error when dialing a remote

Hi all,

I am still a complete noob in libp2p, so this is probably a very dumb question, but I can’t find any information on why this error happens anywhere. I wrote a go function to simplify dialing a remote node, like this:

func GetStreamToRemoteNode(dialer host.Host, remote_addr peerstore.ID) (*bufio.ReadWriter, error) {

	addr, addrErr := multiaddr.NewMultiaddr(string(remote_addr))
	if addrErr != nil {
		return nil, addrErr

	peer, infoErr := peerstore.AddrInfoFromP2pAddr(addr)
	if infoErr != nil {
		return nil, infoErr

	dialer.Peerstore().AddAddrs(peer.ID, peer.Addrs, store.PermanentAddrTTL)
	peers := dialer.Peerstore().PeersWithKeys() // I can see the peer I just added here.
	stream, dialErr := dialer.NewStream(context.Background(), remote_addr, CachengoProtocolID)
	if dialErr != nil {
		return nil, dialErr
	rw := bufio.NewReadWriter(bufio.NewReader(stream), bufio.NewWriter(stream))
	return rw, nil

However, I am getting a “no addresses” error message on the line that calls dialer.NewStream(). I am basing this on the chat example available on the go-libp2p repo examples folder. The example suggests that I need to call dialer.Peerstore().AddAddrs() before NewStream(), which I did. I can also see that the peer’s address is added to the peerstore when I debug the function. Can someone please explain what this error message means and what I am doing wrong? Any help will be greatly appreciated.

Found the problem. When calling NewStream() I needed to pass in peer.ID, instead of remote_addr.