Libra SDK for Go

I wanted to play around with Libra a little bit, but not only manually via CLI, but also programmatically.

In Libra clients for other languages it was mentioned that no clients / SDKs for languages other than Rust exist yet, but that gRPC can be used.

So I started implementing a Go SDK that connects to a validator node via gRPC and can get the account state, send transactions etc.

It’s really basic so far and the API will definitely break in future releases, but at least you can play around with it already like this:

package main

import (
	"fmt"
	"time"

	libra "github.com/philippgille/libra-sdk-go"
)

func main() {
	c, err := libra.NewClient("ac.testnet.libra.org:8000", time.Second)
	if err != nil {
		panic(err)
	}
	defer c.Close()

	accState, err := c.GetAccountState("8cd377191fe0ef113455c8e8d769f0c0147d5bb618bf195c0af31a05fbfd0969")
	if err != nil {
		panic(err)
	}

	fmt.Printf("Account state: 0x%x", accState)
}

I will implement decoding those bytes soon(™), and will also work on making sending a transaction easier, as well as add more features (like creating a wallet / keypairs from a recovery seed).

This is the repository: https://github.com/philippgille/libra-sdk-go/

I’d love to hear feedback and work together with some other Gophers in this community to move the project foward.

4 Likes

I’m planning on implementing something in Go too - I’ll leverage the gRPC bindings; but, 'm working on doing key generation and signing/verification natively. I’ll release something raw this week. It’d be great to be able to share notes, so please touch base if you wish.

1 Like

but, 'm working on doing key generation and signing/verification natively

The current version is just the starting point from what I got done on the weekend. As I mentioned in the forum post and in the repository’s README, those will be added to the SDK as well.

Quote:

I will implement decoding those bytes soon(™), and will also work on making sending a transaction easier, as well as add more features (like creating a wallet / keypairs from a recovery seed).

And from the roadmap in the README:

  • Instead of the current Transaction struct that only takes RawBytes , a higher level transaction struct will be added with fields for the sender and receiver address as well as amount of Libra Coins to send.

(Which requires the signing part that you mentioned)

So maybe we can join forces?

1 Like

Sounds good - my project is more narrow in scope than yours, but there is definitely overlap.

I implemented decoding the account state blob into a proper object of a struct, so now you can do this:

c, _ := libra.NewClient("ac.testnet.libra.org:8000", time.Second)
defer c.Close()
accState, _ := c.GetAccountState("8cd377191fe0ef113455c8e8d769f0c0147d5bb618bf195c0af31a05fbfd0969")
fmt.Printf("Account resource: %v", accState.AccountResource)

And that prints:

{“authentication_key”: “0x8cd377191fe0ef113455c8e8d769f0c0147d5bb618bf195c0af31a05fbfd0969”, “balance”: “62500000”, “received_events_count”: “1”, “sent_events_count”: “4”, “sequence_number”: “4”}

The individual fields are accessible as well of course (balance etc.).

It’s on the master branch and will be included in the next release.

@cypherhat: Do you already have something for creating keypairs from a mnemonic seed phrase or for signing transactions?

I do, though, I still have some final testing. You can check out my code: https://github.com/immutability-io/vault-libra/blob/master/libra/keypair.go