package module
Version: v0.0.0-...-ecf721b Latest Latest

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 6 Imported by: 0



Go Report Card GoDoc


  • 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 (

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





	primary, _ := W.PrimaryAddress()

	addresses, _ := W.Addresses()






	/* example sending an advanced transaction
				"address": "TRTLuySpDqd2fcvq5vx7Jiayw6yao7JHXFPuia5V83cVREtQSKyvWpxX9vamnUcG35BkQy6VfwUy5CsV9YNomioPGGyVhK3YXLq",
				"amount":  100,
		nil, nil, []string{primary}, nil, nil, nil,


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

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

	fmt.Println("Deleted address:", addr)


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




View Source
const (
	MIXIN = 3
	FEE   = 10



View Source
var ERRORS = map[int]string{
	400: "A parse error occurred, or an error occurred processing your request.",
	401: "API key is missing or invalid.",
	403: "This operation requires a wallet to be open, and one has not been opened.",
	404: "The transaction hash was not found.",
	500: "An exception was thrown whilst processing the request.",

ERRORS - wallet-api errors


This section is empty.


type AddressInfo

type AddressInfo struct {
	IsIntegrated   bool
	PaymentID      string
	ActualAddress  string
	PublicSpendKey string
	PublicViewKey  string

AddressInfo - response from validate address

type Balance

type Balance struct {
	Unlocked uint64 `json:"unlocked"`
	Locked   uint64 `json:"locked"`
	Address  string `json:"address"`

Balance - represents a wallet balance

type NodeInfo

type NodeInfo struct {
	DaemonHost  string `json:"daemonHost"`
	DaemonPort  int64  `json:"daemonPort"`
	NodeFee     int64  `json:"nodeFee"`
	NodeAddress string `json:"nodeAddress"`

NodeInfo - node response

type Status

type Status struct {
	NetworkBlockCount uint64 `json:"networkBlockCount"`
	WalletBlockCount  uint64 `json:"walletBlockCount"`
	LocalBlockCount   uint64 `json:"localDaemonBlockCount"`
	PeerCount         uint64 `json:"peerCount"`
	Hashrate          uint64 `json:"hashrate"`
	IsViewWallet      bool   `json:"isViewWallet"`
	SubWalletCount    uint64 `json:"subWalletCount"`

Status - represents a status object

type Transaction

type Transaction struct {
	BlockHeight           uint64     `json:"blockHeight"`
	Fee                   uint64     `json:"fee"`
	FeePerByte            uint64     `json:"feePerByte"`
	Hash                  string     `json:"hash"`
	IsCoinbaseTransaction bool       `json:"isCoinbaseTransaction"`
	PaymentID             string     `json:"paymentID"`
	Timestamp             uint64     `json:"timestamp"`
	UnlockTime            uint64     `json:"unlockTime"`
	Transfers             []Transfer `json:"transfers"`

Transaction - represents a transaction object

type TransactionResult

type TransactionResult struct {
	TransactionHash  string `json:"transactionHash"`
	Fee              uint64 `json:"fee"`
	RelayedToNetwork bool   `json:"relayedToNetwork"`

TransactionResult - represents the result of a sent / prepared transaction

type Transactions

type Transactions struct {
	Transactions []Transaction `json:"transactions"`
	Transaction  Transaction   `json:"transaction"`

Transactions - represents a transactions object

type Transfer

type Transfer struct {
	Address string `json:"address"`
	Amount  int64  `json:"amount"`

Transfer - represents a transfer object

type Wallet

type Wallet struct {
	DaemonHost string
	DaemonPort int
	Filename   string
	Password   string

Wallet - holds wallet configuration

type WalletAPI

type WalletAPI struct {
	APIKey string
	Host   string
	Port   string

WalletAPI - communicates with wallet-api

func InitWalletAPI

func InitWalletAPI(apiKey, host, port string) *WalletAPI

InitWalletAPI - initializes wallet-api connection

func (WalletAPI) Addresses

func (wAPI WalletAPI) Addresses() ([]string, error)

Addresses - gets all the addresses in the wallet container

func (WalletAPI) CloseWallet

func (wAPI WalletAPI) CloseWallet() error

CloseWallet - saves and closes the wallet

func (WalletAPI) CreateAddress

func (wAPI WalletAPI) CreateAddress() (map[string]string, error)

CreateAddress - creates a new random address in the wallet container

func (WalletAPI) CreateIntegratedAddress

func (wAPI WalletAPI) CreateIntegratedAddress(address, paymentID string) (string, error)

CreateIntegratedAddress - creates an integrated address from and address and paymentID

func (WalletAPI) CreateWallet

func (wAPI WalletAPI) CreateWallet(wallet *Wallet) error

CreateWallet - creates a new wallet

func (WalletAPI) DeleteAddress

func (wAPI WalletAPI) DeleteAddress(address string) error

DeleteAddress - deletes a subwallet in the wallet container

func (WalletAPI) DeletePreparedTransaction

func (wAPI WalletAPI) DeletePreparedTransaction(hash string) error

DeletePreparedTransaction - removes a previously created prepared transaction

func (WalletAPI) GetAddressBalance

func (wAPI WalletAPI) GetAddressBalance(address string) (bal *Balance, err error)

GetAddressBalance - gets the balance for the specified wallet address

func (WalletAPI) GetAddressTransactionsByStartHeight

func (wAPI WalletAPI) GetAddressTransactionsByStartHeight(address string, startHeight uint64) (txs *[]Transaction, err error)

GetAddressTransactionsByStartHeight - gets 1000 transactions for the address starting at startHeight

func (WalletAPI) GetAddressTransactionsInRange

func (wAPI WalletAPI) GetAddressTransactionsInRange(address string, start, end uint64) (txs *[]Transaction, err error)

GetAddressTransactionsInRange - gets transactions for the address given a range of block heights

func (WalletAPI) GetAllTransactions

func (wAPI WalletAPI) GetAllTransactions() (txs *[]Transaction, err error)

GetAllTransactions - gets all the transactions in the wallet container

func (WalletAPI) GetBalance

func (wAPI WalletAPI) GetBalance() (unlocked, locked uint64, err error)

GetBalance - gets the balance for the entire wallet container

func (WalletAPI) GetBalances

func (wAPI WalletAPI) GetBalances() ([]Balance, error)

GetBalances - gets the balance for the every wallet address

func (WalletAPI) GetKeys

func (wAPI WalletAPI) GetKeys(address string) (publicSpendKey, privateSpendKey string, err error)

GetKeys - gets the public and private view key for the given address

func (WalletAPI) GetMnemonic

func (wAPI WalletAPI) GetMnemonic(address string) (string, error)

GetMnemonic - gets the mnemonic seed for the given address

func (WalletAPI) GetTransactionByHash

func (wAPI WalletAPI) GetTransactionByHash(hash string) (tx *Transaction, err error)

GetTransactionByHash - gets the transaction with the given hash in the wallet container

func (WalletAPI) GetTransactionPrivateKey

func (wAPI WalletAPI) GetTransactionPrivateKey(hash string) (string, error)

GetTransactionPrivateKey - gets the private key of a transaction with the given hash

func (WalletAPI) GetTransactionsByStartHeight

func (wAPI WalletAPI) GetTransactionsByStartHeight(startHeight uint64) (txs *[]Transaction, err error)

GetTransactionsByStartHeight - gets 1000 transactions for the wallet starting at startHeight

func (WalletAPI) GetTransactionsInRange

func (wAPI WalletAPI) GetTransactionsInRange(start, end uint64) (txs *[]Transaction, err error)

GetTransactionsInRange - gets transactions for the wallet given a range of block heights

func (WalletAPI) GetUnconfirmedTransactions

func (wAPI WalletAPI) GetUnconfirmedTransactions() (txs *[]Transaction, err error)

GetUnconfirmedTransactions - gets all unconfirmed outgoing transactions

func (WalletAPI) GetUnconfirmedTransactionsByAddress

func (wAPI WalletAPI) GetUnconfirmedTransactionsByAddress(address string) (txs *[]Transaction, err error)

GetUnconfirmedTransactionsByAddress - gets all unconfirmed outgoing transactions for a given address

func (WalletAPI) ImportAddress

func (wAPI WalletAPI) ImportAddress(spendKey string, scanHeight uint64) (string, error)

ImportAddress - import a subwallet with the given private spend key

func (WalletAPI) ImportKey

func (wAPI WalletAPI) ImportKey(wallet *Wallet, viewKey, spendKey string, scanHeight uint64) error

ImportKey - imports a wallet with a private spend and view key

func (WalletAPI) ImportSeed

func (wAPI WalletAPI) ImportSeed(wallet *Wallet, mnemonicSeed string, scanHeight uint64) error

ImportSeed - imports a wallet using a mnemonic seed

func (WalletAPI) ImportView

func (wAPI WalletAPI) ImportView(wallet *Wallet, viewKey, address string, scanHeight uint64) error

ImportView - imports a view only wallet using

func (WalletAPI) ImportViewAddress

func (wAPI WalletAPI) ImportViewAddress(spendKey string, scanHeight uint64) (string, error)

ImportViewAddress - import a view only subwallet with the given public spend key

func (WalletAPI) Node

func (wAPI WalletAPI) Node() (*NodeInfo, error)

Node - gets the node address, port, fee, and fee address

func (WalletAPI) OpenWallet

func (wAPI WalletAPI) OpenWallet(wallet *Wallet) error

OpenWallet - opens an existing wallet

func (WalletAPI) PrepareTransactionAdvanced

func (wAPI WalletAPI) PrepareTransactionAdvanced(
	destinations []map[string]interface{},
	mixin, fee, feePerByte, sourceAddresses, paymentID, changeAddress, unlockTime interface{}) (tx *TransactionResult, err error)

PrepareTransactionAdvanced - creates a transaction but does not relay it to the network

func (WalletAPI) PrepareTransactionBasic

func (wAPI WalletAPI) PrepareTransactionBasic(destination string, amount uint64, paymentID string) (*TransactionResult, error)

PrepareTransactionBasic - creates a transaction but does not relay it to the network

func (WalletAPI) PrimaryAddress

func (wAPI WalletAPI) PrimaryAddress() (string, error)

PrimaryAddress - gets the primary address in the wallet container

func (WalletAPI) Reset

func (wAPI WalletAPI) Reset(scanHeight uint64) error

Reset - resets and saves the wallet

func (WalletAPI) Save

func (wAPI WalletAPI) Save() error

Save - saves wallet container

func (WalletAPI) SendFusionAdvanced

func (wAPI WalletAPI) SendFusionAdvanced(sourceAddresses []string, destination string) (string, error)

SendFusionAdvanced - sends a fusion transaction

func (WalletAPI) SendFusionBasic

func (wAPI WalletAPI) SendFusionBasic() (string, error)

SendFusionBasic - sends a fusion transaction

func (WalletAPI) SendPreparedTransaction

func (wAPI WalletAPI) SendPreparedTransaction(hash string) (string, error)

SendPreparedTransaction - sends a previously created prepared transaction

func (WalletAPI) SendTransactionAdvanced

func (wAPI WalletAPI) SendTransactionAdvanced(
	destinations []map[string]interface{},
	mixin, fee, feePerByte, sourceAddresses, paymentID, changeAddress, unlockTime interface{}) (tx *TransactionResult, err error)

SendTransactionAdvanced - sends a transaction

func (WalletAPI) SendTransactionBasic

func (wAPI WalletAPI) SendTransactionBasic(destination, paymentID string, amount uint64) (string, error)

SendTransactionBasic - sends a transaction

func (WalletAPI) SetNode

func (wAPI WalletAPI) SetNode(daemonHost string, daemonPort int) error

SetNode - sets the node address and port

func (WalletAPI) Status

func (wAPI WalletAPI) Status() (*Status, error)

Status - gets the wallet status

func (WalletAPI) ValidateAddress

func (wAPI WalletAPI) ValidateAddress(address string) (*AddressInfo, error)

ValidateAddress - validates an address

func (WalletAPI) ViewKey

func (wAPI WalletAPI) ViewKey() (string, error)

ViewKey - gets the private view key of the wallet container

Jump to

Keyboard shortcuts

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