libra-go

module
v0.0.0-...-194be82 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: MIT

README

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

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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