Gowaves: Golang Waves library

Hello everybody!

We just started to implement a new Waves library, this time using Go programming language. It’s in an early stage of development, and you can track our progress on Github.

  • Crypto used in Waves, already in the repo along with some basic primitives.
  • Next, we are planning to implement a binary representation of all transaction types and network messages.
  • After that, we implement an HTTP client to node’s API.
  • Also, we will develop a few utilities which will be useful as examples and by itself.

Comments, feature or bug requests are welcome here or on Github.

gowaves library was updated to support the InvokeScript transaction.

Here is the simple example of how to create and broadcast an InvokeScript transaction.

package main

import (
	"context"
	"net/http"
	"time"

	"github.com/wavesplatform/gowaves/pkg/client"
	"github.com/wavesplatform/gowaves/pkg/crypto"
	"github.com/wavesplatform/gowaves/pkg/proto"
)

func main() {
	// Create sender's public key from BASE58 string
	sender, err := crypto.NewPublicKeyFromBase58("<your-public-key>")
	if err != nil {
		panic(err)
	}

	// Create sender's private key from BASE58 string
	sk, err := crypto.NewSecretKeyFromBase58("<your-private-key>")
	if err != nil {
		panic(err)
	}

	// Create script's address
	a, err := proto.NewAddressFromString("<script's address")
	if err != nil {
		panic(err)
	}

	// Create Function Call that will be passed to the script
	fc := proto.FunctionCall{
		Name: "foo",
		Arguments: proto.Arguments{
			proto.IntegerArgument{
				Value: 12345,
			},
			proto.BooleanArgument{
				Value: true,
			},
		},
	}

	// Current time in milliseconds
	ts := time.Now().Unix() * 1000

	// Fee asset is Waves
	waves := proto.OptionalAsset{Present: false}

	// New InvokeScript Transaction
	tx, err := proto.NewUnsignedInvokeScriptV1('T', sender, a, fc, proto.ScriptPayments{}, waves, 500000, uint64(ts))
	if err != nil {
		panic(err)
	}

	// Sing the transaction with the private key
	err = tx.Sign(sk)

	// Create new HTTP client to send the transaction to public TestNet nodes
	client, err := client.NewClient(client.Options{BaseUrl: "https://testnodes.wavesnodes.com", Client: &http.Client{}})
	if err != nil {
		panic(err)
	}

	// Context to cancel the request execution on timeout
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	// Send the transaction to the network
	_, err = client.Transactions.Broadcast(ctx, tx)
	if err != nil {
		panic(err)
	}
}

Please, check out the latest version on Github.
If you have any questions about gowaves feel free to ask them here or in Github issues.

These libraries help you to get the code small and let you use lots of function.