trongrid

package module
v0.0.0-...-31f9ead Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 10 Imported by: 0

README

TronGrid API

⭐ Star us on GitHub — it motivates us a lot!

Go/Golang library for the TronGrid API.

Table of Content

Features

  • List Transactions

Usage/Examples

List Transactions
package main

import (
	"context"
	"os"
	"time"

	"github.com/rs/zerolog"

	"github.com/LipsarHQ/go-trongrid"
)

const token = "13f70f8e-65ff-49d2-a218-7cf3fadf6230"

func main() {
	logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger()
	api := trongrid.NewAPI(
		trongrid.WithDebug(),
		trongrid.WithLogger(&logger),
		trongrid.WithToken(token),
	)

	ctx := context.Background()
	now := time.Now()

	// List transactions.
	modelListTransactionsRequest, err := api.ListTransactions(ctx, &trongrid.ListTransactionsRequest{
		MaxTimestamp:  now.Add(-(time.Hour * 24)),
		MinTimestamp:  now,
		Address:       "TWpMnUh9pZS1Mf8yyw9WPiS82WYevKzQo2",
		Fingerprint:   "",
		OrderBy:       "block_timestamp,desc",
		Limit:         2,
		OnlyConfirmed: true,
		OnlyFrom:      false,
		OnlyTo:        false,
	})
}

License

MIT

Documentation

Index

Constants

View Source
const URI = "https://api.trongrid.io/"

Variables

View Source
var ErrEmpty = errors.New("")

Functions

func NewDecoder

func NewDecoder() *schema.Decoder

func NewEncoder

func NewEncoder() *schema.Encoder

func NewLogger

func NewLogger(l *zerolog.Logger) resty.Logger

Types

type API

type API interface {
	// ListTransactions
	// Docs: https://developers.tron.network/reference/get-trc20-transaction-info-by-account-address
	ListTransactions(
		ctx context.Context,
		req *ListTransactionsRequest,
	) (resp *ListTransactionsResponse, err error)
}

func NewAPI

func NewAPI(opts ...Option) API

type Error

type Error struct {
	Error string `json:"error"`
}

type ListTransactionsRequest

type ListTransactionsRequest struct {
	MaxTimestamp  time.Time `url:"max_timestamp,omitempty"`
	MinTimestamp  time.Time `url:"min_timestamp,omitempty"`
	Address       string    `url:"Address,omitempty"`
	Fingerprint   string    `url:"fingerprint,omitempty"`
	OrderBy       string    `url:"order_by,omitempty"`
	Limit         int32     `url:"limit,omitempty"`
	OnlyConfirmed bool      `url:"only_confirmed,omitempty"`
	OnlyFrom      bool      `url:"only_from,omitempty"`
	OnlyTo        bool      `url:"only_to,omitempty"`
}

type ListTransactionsResponse

type ListTransactionsResponse struct {
	Meta    *Meta          `json:"meta"`
	Data    []*Transaction `json:"data"`
	Success bool           `json:"success"`
}

type Meta

type Meta struct {
	Links       *MetaLinks `json:"links"`
	Fingerprint string     `json:"fingerprint"`
	At          int64      `json:"at"`
	PageSize    int32      `json:"page_size"`
}
type MetaLinks struct {
	Next string `json:"next"`
}

type Option

type Option func(api *api)

func WithDebug

func WithDebug() Option

func WithLogger

func WithLogger(logger *zerolog.Logger) Option

func WithToken

func WithToken(token string) Option

func WithURI

func WithURI(uri string) Option

type Token

type Token struct {
	Address  string `json:"address"`
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
	Decimals int32  `json:"decimals"`
}

type Transaction

type Transaction struct {
	Token          *Token          `json:"token_info"`
	From           string          `json:"from"`
	ID             string          `json:"transaction_id"`
	To             string          `json:"to"`
	Type           TransactionType `json:"type"`
	Value          string          `json:"value"`
	BlockTimestamp int64           `json:"block_timestamp"`
}

type TransactionType

type TransactionType string
const TransactionTypeTransfer TransactionType = "Transfer"

Jump to

Keyboard shortcuts

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