Giter VIP home page Giter VIP logo

libra-go's Introduction

Libra Golang Client

Libra Golang Client is library to interact with Libra Blockchain

Note: The project is still under major development! The Package is not stable and will keep changing!

Installation

To install run:

go get github.com/codemaveric/libra-go/pkg/goclient

Usage

Example

package main

import (
	"log"
	"strings"

	"github.com/codemaveric/libra-go/pkg/goclient"
	"github.com/codemaveric/libra-go/pkg/librawallet"
)

func main() {
 	// I will advice you to change the mnemonic to something else
	mnemonic := "present good satochi coin future media giant"
	wallet := librawallet.NewWalletLibrary(mnemonic)
	address, childNum, err := wallet.NewAddress()
	if err != nil {
		log.Fatal(err)
	}
	log.Print(address.ToString())

	// Generate Keypair with mnemonic and childNum
	keyPair := librawallet.GenerateKeyPair(strings.Split(mnemonic, " "), childNum)

	// Create Account from KeyPair
	sourceAccount := librawallet.NewAccountFromKeyPair(keyPair)
	// Libra Client Configuration
	config := goclient.LibraClientConfig{
		Host:    "ac.testnet.libra.org",
		Port:    "80",
		Network: goclient.TestNet,
	}
	// Instantiate LibraClient with Configuration.
	libraClient := goclient.NewLibraClient(config)

	// Mint Coin from Test Faucet to account generated.
	err = libraClient.MintWithFaucetService(sourceAccount.Address.ToString(), 500000000, true)

	if err != nil {
		log.Fatal(err)
	}

	// Get Account State.
	SourceaccState, err := libraClient.GetAccountState(sourceAccount.Address.ToString())
	if err != nil {
		log.Fatal(err)
	}
	log.Print(SourceaccState.Balance)

	// Set the current account sequence.
	sourceAccount.Sequence = SourceaccState.SequenceNumber

	// Transfer Coins from source account to destination address.
	err = libraClient.TransferCoins(sourceAccount, "f4aebe371e4176143c3409122d0adf43c0e00a6552b5b0ae9980d8981fcd0221", 11000000, 0, 10000, true)
	if err != nil {
		log.Fatal(err)
	}
	
	// Get Account Transaction by Sequence Number.
	transaction, err := libraClient.GetAccountTransaction(sourceAccount.Address.ToString(), 0, true)

	if err != nil {
		log.Fatal(err)
	}

	log.Println(transaction)
}

Contribution

Feel free to contribute by opening issues or PR's.

License

MIT

libra-go's People

Contributors

codemaveric avatar lunaticf avatar smallnest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

libra-go's Issues

run example main codes

Getting the following error

github.com/codemaveric/libra-go/pkg/librawallet

../../../go/src/github.com/codemaveric/libra-go/pkg/librawallet/keyfactory.go:61:13: undefined: hkdf.Extract
../../../go/src/github.com/codemaveric/libra-go/pkg/librawallet/keyfactory.go:69:7: undefined: hkdf.Expand

Create Examples

Summary

Create a folder example containing different examples of how to interact with Libra Blockchain using Golang.

  • Create Account, Get Account from Keypair and hex string of private key
  • Get Account State
  • Mint Coins from Test Faucet
  • Transfer Coins
  • Get Transaction Details

Add topics of project

Maybe add some topics like blockchain or libra? Think it will help people find this repo.

Issue when getting libra-go package

Hi,

I get the following error when executing go get github.com/codemaveric/libra-go:

$ go get github.com/codemaveric/libra-go
can't load package: package github.com/codemaveric/libra-go: no Go files in <path-to-home>/go/src/github.com/codemaveric/libra-go

Is this something related with the package or from my own configuration?
Sorry if this is not related with libra-go but I'm pretty new to Go.
Regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.