Skip to content

Latest commit

 

History

History
107 lines (82 loc) · 2.99 KB

README.md

File metadata and controls

107 lines (82 loc) · 2.99 KB

go-electrum GoDoc

A pure Go Electrum bitcoin library. This makes it easy to write bitcoin based services using Go without having to run a full bitcoin node.

go-electrum

This is very much WIP and has a number of unimplemented methods. This will eventually be rewritten into a more Go-esque library and handle wallet generation.

Packages provided

  • electrum - Library for using JSON-RPC to talk directly to Electrum servers.
  • wallet - A bitcoin wallet built on btcwallet with Electrum as the backend.
  • irc - A helper module for finding electrum servers using the #electrum IRC channel on Freenode.

Usage

See example/ for more.

electrum GoDoc

$ go get -u github.com/d4l3k/go-electrum/electrum
package main

import (
  "log"

  "github.com/d4l3k/go-electrum/electrum"
)

func main() {
	node := electrum.NewNode()
	if err := node.ConnectTCP("electrum.dragonzone.net:50001"); err != nil {
		log.Fatal(err)
	}
	balance, err := node.BlockchainAddressGetBalance("1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L")
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Address balance: %+v", balance)
}

wallet GoDoc

$ go get -u github.com/d4l3k/go-electrum/wallet
package main

import (
  "log"

  "github.com/btcsuite/btcutil"
  "github.com/d4l3k/go-electrum/wallet"
)

func main() {
  seed, err := hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen)
  if err != nil {
    log.Fatal(err)
  }
  w, err := wallet.Create("test.wallet", "pass", seed)
  if err != nil {
    log.Fatal(err)
  }
  addrs, err := w.GenAddresses(1)
  if err != nil {
    log.Fatal(err)
  }
  log.Printf("Address: %s", addrs[0])
  err = w.SendBitcoin(map[string]btcutil.Amount{
    "18mS21JLSWJcTwKV8ZEv5SvroKAqkbYfPy": btcutil.NewAmount(1.0),
  }, 6)
  if err != nil {
    log.Fatal(err)
  }
}

irc GoDoc

$ go get -u github.com/d4l3k/go-electrum/irc
package main

import (
	"log"

	"github.com/d4l3k/go-electrum/irc"
)

func main() {
	log.Println(irc.FindElectrumServers())
}

License

go-electrum is licensed under the MIT license.

Made by Tristan Rice.