by multiformats

multiformats / go-multiaddr

Composable and future-proof network addresses

138 Stars 49 Forks Last release: 2 months ago (v0.3.1) MIT License 433 Commits 33 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


GoDoc Travis CI codecov.io

multiaddr implementation in go

Multiaddr is a standard way to represent addresses that:

  • Support any standard network protocols.
  • Self-describe (include protocols).
  • Have a binary packed format.
  • Have a nice string representation.
  • Encapsulate well.

Table of Contents


go get github.com/multiformats/go-multiaddr




import ma "github.com/multiformats/go-multiaddr"

// construct from a string (err signals parse failure) m1, err := ma.NewMultiaddr("/ip4/")

// construct from bytes (err signals parse failure) m2, err := ma.NewMultiaddrBytes(m1.Bytes())

// true strings.Equal(m1.String(), "/ip4/") strings.Equal(m1.String(), m2.String()) bytes.Equal(m1.Bytes(), m2.Bytes()) m1.Equal(m2) m2.Equal(m1)


// get the multiaddr protocol description objects
// []Protocol{
//   Protocol{ Code: 4, Name: 'ip4', Size: 32},
//   Protocol{ Code: 17, Name: 'udp', Size: 16},
// }


import ma "github.com/multiformats/go-multiaddr"

m, err := ma.NewMultiaddr("/ip4/") //

sctpMA, err := ma.NewMultiaddr("/sctp/5678")

m.Encapsulate(sctpMA) //

udpMA, err := ma.NewMultiaddr("/udp/1234")

m.Decapsulate(udpMA) // up to + inc last occurrence of subaddr //


Multiaddr allows expressing tunnels very nicely.

printer, _ := ma.NewMultiaddr("/ip4/")
proxy, _ := ma.NewMultiaddr("/ip4/")
printerOverProxy := proxy.Encapsulate(printer)
// /ip4/

proxyAgain := printerOverProxy.Decapsulate(printer) // /ip4/


Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.


MIT © 2014 Juan Batiz-Benet

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.