Tezos
$1.65 0.58%
XTZ · 2w

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.58% · twitter.com · 12h

Great News: Tezos' Athens Amendment has Passed!

Breaking: the digital commonwealth's first on-chain proposal has been successful. Stakeholders of the #Tezos network have voted for the so-called Athens amendment to pass, thereby upgrading the protoc...
XTZ +0.58% · twitter.com · 16h

Coinbase attending at Tezos Tokyo Meetup May 28, 2019

Excited to discuss Coinbase Custody's Tezos staking support at the upcoming Tezos Tokyo Meetup! 東京テゾス会議 https://t.co/XgNjlX3k3n #Meetup #Tōkyō-to via @Meetup— Kayvon Pirestani (@kpiresta) May 21, 2019...