Skip to content
Go Wrapper for the TurtleCoin wallet-api
Branch: master
Clone or download
Pull request Compare This branch is even with anonanonymous:master.
Latest commit 8882491 Jun 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml
LICENSE Initial commit May 4, 2019
README.md Update README.md Jun 8, 2019
addresses.go change int64 to uint64, add validateAddress May 7, 2019
balance.go return a Balance struct, add test May 11, 2019
errors.go add Readme May 7, 2019
keys.go initial commit May 5, 2019
misc.go return struct Jun 8, 2019
node.go return NodeInfo struct, add test May 14, 2019
transactions.go switch amount to int64 May 8, 2019
utils.go use 400 error message May 8, 2019
wallet-api.go initial commit May 5, 2019
wallet.go change int64 to uint64, add validateAddress May 7, 2019
walletapi_test.go return struct Jun 8, 2019

README.md

wallet-api-go

Go Report Card GoDoc

Prerequisites

  • Go compiler
  • wallet-api daemon

Getting Started

Start the wallet-api daemon in a separate terminal window.

./wallet-api -r password

Then make and switch to directory named test

mkdir test && cd $_

Create main.go with the following contents. Edit the wallet configuration if neccessary.

package main

import (
	"fmt"
	"os"
	"github.com/anonanonymous/wallet-api-go"
)

func main() {
	wd, _ := os.Getwd()
	wallet := walletapi.Wallet{
		Filename:   wd+"/test.wallet",
		Password:   "password",
		DaemonHost: "public.turtlenode.io",
		DaemonPort: 11898,
	}
	W := walletapi.InitWalletAPI("password", "127.0.0.1", "8070")

	fmt.Println("====CreateWallet====")
	fmt.Println(W.CreateWallet(&wallet))

	fmt.Println("====Status====")
	fmt.Println(W.Status())

	fmt.Println("====Node====")
	fmt.Println(W.Node())

	fmt.Println("====ViewKey====")
	fmt.Println(W.ViewKey())

	fmt.Println("====PrimaryAddress===")
	primary, _ := W.PrimaryAddress()
	fmt.Println(primary)

	fmt.Println("====Addresses====")
	addresses, _ := W.Addresses()
	fmt.Println(addresses)

	fmt.Println("====ValidateAddress====")
	fmt.Println(W.ValidateAddress(primary))

	fmt.Println("====GetBalance====")
	fmt.Println(W.GetBalance())

	fmt.Println("====GetBalances====")
	fmt.Println(W.GetBalances())

	fmt.Println("====GetKeys====")
	fmt.Println(W.GetKeys(primary))

	fmt.Println("====GetMnemonic====")
	fmt.Println(W.GetMnemonic(primary))

	/* example sending an advanced transaction
	fmt.Println("====SendTransactionAdvanced====")
	fmt.Println(W.SendTransactionAdvanced(
		[]map[string]interface{}{
			map[string]interface{}{
				"address": "TRTLuySpDqd2fcvq5vx7Jiayw6yao7JHXFPuia5V83cVREtQSKyvWpxX9vamnUcG35BkQy6VfwUy5CsV9YNomioPGGyVhK3YXLq",
				"amount":  100,
			},
		},
		nil, nil, []string{primary}, nil, nil, nil,
	))
	*/

	fmt.Println("====GetAllTransactions====")
	fmt.Println(W.GetAllTransactions())

	fmt.Println("====GetTransactionByHash====")
	fmt.Println(W.GetTransactionByHash("invalid hash"))

	fmt.Println("===GetTransactionPrivateKey====")
	fmt.Println(W.GetTransactionPrivateKey("invalid hash"))

	addr, _ := W.CreateAddress()
	fmt.Println("Created address:", addr)

	fmt.Println("====GetAddressTransactionsByStartHeight - primary wallet address====")
	fmt.Println(W.GetAddressTransactionsByStartHeight(primary, 1000))

	fmt.Println("====GetAddressTransactionsByStartHeight - new wallet address====")
	fmt.Println(W.GetAddressTransactionsByStartHeight(addr["address"], 1000))

	W.DeleteAddress(addr["address"])
	fmt.Println("Deleted address:", addr)

	W.CloseWallet()
	fmt.Println("====Done====")
}

Build and run the example program
go mod init github.com/anonanonymous/test
go build; ./test

You can’t perform that action at this time.