Tezos
$1.07 -0.92%
XTZ · 19w

Go Tezos Major Release v1.0.0 - A Tezos Golang Library

A Tezos Go Library

Go Tezos is a GoLang driven library for your Tezos node.

Installation

Get goTezos

go get github.com/DefinitelyNotAGoat/go-tezos Getting Started

Go Tezos is split into multiple services underneath to help organize it’s functionality and also makes the library easier to maintain.

To understand how Go Tezos works, take a look at the GoTezos Structure:

type GoTezos struct { client *client Constants NetworkConstants Block *BlockService SnapShot *SnapShotService Cycle *CycleService Account *AccountService Delegate *DelegateService Network *NetworkService Operation *OperationService Contract *ContractService }

You can see GoTezos is a wrapper for an http client, and services such as block, SnapShot, Cycle, Account, Delegate, Network, Operation, and Contract.

The below examples assume you have go-tezos imported as follows:

import ( goTezos "github.com/DefinitelyNotAGoat/go-tezos" ) Initializing Go Tezos

Currently you must initialize with http:// or https://

gt, err := NewGoTezos("http://127.0.0.1:8732") if err != nil { fmt.Printf("could not connect to network: %v", err) } Setting Your Own HTTP Client

If you don’t want to use Go Tezos’s default HTTP Client you can set your own.

var client *http.Client ..... ..... ..... gt.SetHTTPClient(client) Blocks

When getting a block, the Block structure will be returned, which contains all the normal fields as hitting the Tezos RPC directly.

Getting A Block By Level or Hash

This function will get a block by a level (int) or hash (string).

block, err := gt.Block.Get(1000) if err != nil { fmt.Println(err) } fmt.Println(block) block, err = gt.Block.Get("BKp1oX19NAAXdj3vU82sbpUrn5hAy51YnVtF5A5StsJKPKQGg3R") if err != nil { fmt.Println(err) } Getting The Head Block

This function will get the current head block of the chain.

block, err := gt.Block.GetHead() if err != nil { fmt.Printl...
Continue on definitelynotagoat.github.io
Recent news
XTZ -0.92% · tezos.foundation · 15h

Tezos Foundation Weekly Update: Week of September 16

Dear Tezos community, Congratulations on the one-year anniversary of Tezos becoming mainnet! We have a lot to look forward to as we stand at the one-year mark of mainnet. The TQuorum Global Summit beg...
XTZ -0.92% · medium.com · 21h

On Babylon2.0.1

Babylon2.0 is the proposal undergoing the testing phase of the Tezos on-chain governance process. In parallel, Nomadic and Cryptium Labs have not only been working on upcoming potential features, but