cryptocurrency

package module
Version: v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2020 License: MIT Imports: 5 Imported by: 1

README

GitHub Actions GoDoc Go Report Card Donate Donate

Cryptocurrency API

Stateless cryptocurrency API.

Requirements:

  • Bitcoin: electrum wallet in $PATH
  • Ethereum: export INFURA_API_KEY=... from infura.io (it's free). It'll work even without, but there are some limits on queries.

Start:

go get -u code.dumpstack.io/lib/cryptocurrency
go test -v code.dumpstack.io/lib/cryptocurrency/...

Usage:

package main

import (
	"log"

	"code.dumpstack.io/lib/cryptocurrency"
)

func main() {
	c := cryptocurrency.Bitcoin
	dest := "mk84dHbQoUHWaWGuYspx6GXWgcjB9CuQqw"
	// c := cryptocurrency.Ethereum
	// dest := "0xD98660C76443A8A043a19499048EeC4FB06f2581"
	// c := cryptocurrency.Cardano
	// dest := "Ae2tdPwUPEZ68cfEjZjKKRabiqbazMtP69uGaM2pMZRg87fvn4FGvR95BEV"

	err := c.Testnet(true)
	if err != nil {
		log.Fatal(err)
	}

	seed, address, err := c.GenWallet()
	if err != nil {
		log.Fatal(err)
	}
	log.Println(seed, address)

	balance, err := c.Balance(seed)
	log.Println(balance)
	if err != nil {
		log.Fatal(err)
	}

	valid, err := c.Validate(dest)
	if err != nil {
		log.Fatal(err)
	}
	if valid {
		log.Println("address", dest, "is valid")
	} else {
		log.Fatal("address", dest, "is invalid")
	}

	amount := float64(0.1)
	tx, err := c.Send(seed, dest, amount)
	// tx, err := c.SendUnits(seed, dest, wei) // precise version
	if err != nil {
		log.Println("here it'll exit because there's no money inside new wallet")
		log.Fatal(err)
	}
	log.Println(tx)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cryptocurrencies = []Cryptocurrency{
	Bitcoin,
	Ethereum,
	Cardano,
}

Cryptocurrencies list

Functions

This section is empty.

Types

type Cryptocurrency

type Cryptocurrency int
const (
	Bitcoin Cryptocurrency = iota
	Ethereum
	Cardano
)

func FromSymbol added in v1.4.0

func FromSymbol(symbol string) (cc Cryptocurrency, err error)

func (Cryptocurrency) Balance

func (t Cryptocurrency) Balance(seed string) (amount float64, err error)

Balance of the wallet (not address!)

func (Cryptocurrency) BalanceUnits

func (t Cryptocurrency) BalanceUnits(seed string) (units *big.Int, err error)

BalanceUnits returns the balance of the wallet (not address!) in Satoshi/Wei/etc.

func (Cryptocurrency) GenWallet

func (t Cryptocurrency) GenWallet() (seed, address string, err error)

GenWallet for specified cryptocurrency

func (Cryptocurrency) GetAddress added in v1.4.0

func (t Cryptocurrency) GetAddress(seed string) (address string, err error)

GetAddress for the wallet (can be the same or different every time)

func (Cryptocurrency) MarshalText added in v1.4.0

func (t Cryptocurrency) MarshalText() (b []byte, err error)

func (Cryptocurrency) Send

func (t Cryptocurrency) Send(seed, dest string, amount float64) (tx string, err error)

Send the amount of cryptocurrency to destination address

func (Cryptocurrency) SendAll

func (t Cryptocurrency) SendAll(seed, dest string) (tx string, err error)

SendAll cryptocurrency to destination address

func (Cryptocurrency) SendUnits

func (t Cryptocurrency) SendUnits(seed, dest string, units *big.Int) (tx string, err error)

SendUnits amount of Satoshi/Wei/etc. to the address dest

func (Cryptocurrency) Symbol added in v1.4.0

func (t Cryptocurrency) Symbol() string

Symbol of cryptocurrency (btc, eth, etc.)

func (Cryptocurrency) Testnet

func (t Cryptocurrency) Testnet(state bool) (err error)

Testnet enable or disable

func (*Cryptocurrency) UnmarshalText added in v1.4.0

func (t *Cryptocurrency) UnmarshalText(data []byte) (err error)

func (Cryptocurrency) Validate

func (t Cryptocurrency) Validate(address string) (valid bool, err error)

Validate cryptocurrency address

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL