Stateless cryptocurrency API
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
dump_stack() 1f2ef5df25
Follow redirect
pirms 4 mēnešiem
.github/workflows Follow redirect pirms 4 mēnešiem
bitcoin Increase electrum synchronization timeout to 3 minutes pirms 5 mēnešiem
cardano Generate 15-words mnemonic (#8) pirms 5 mēnešiem
ethereum Support latest infura API pirms 5 mēnešiem
LICENSE Initial pirms 9 mēnešiem
README.md Fix go mod major version pirms 5 mēnešiem
cryptocurrency.go Fix go mod major version pirms 5 mēnešiem
cryptocurrency_test.go Add test pirms 9 mēnešiem
go.mod Fix go mod major version pirms 5 mēnešiem
go.sum Update go-ext-wasm pirms 5 mēnešiem
shell.nix Add copyright pirms 9 mēnešiem

README.md

GitHub Actions GoDoc Go Report Card Donate Donate

Cryptocurrency API

Stateless cryptocurrency API.

Requirements:

  • Bitcoin: electrum wallet in $PATH
  • Ethereum: export INFURA_PROJECT_ID=... 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/v2
go test -v code.dumpstack.io/lib/cryptocurrency/v2/...

Usage:

package main

import (
	"log"

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

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)
}