Tezos
$2.30 -4.75%
XTZ · 82w

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 -4.75% · forum.tezosagora.org · 16h

New Agora topic: Unpatented efforts

The following post contains a proof of concept implemented on Tezos Blockchain. This is a symbiotic system in which a party injects an asset/a file in a Blockchain as a FA2 NFT (Non Fungible Token). ...