Giter Site home page Giter Site logo

ethclient's Introduction

Bundle SDK Ethclient

This is a modified version of the go-ethereum/ethclient package. It is modified to work with the unifra bundle api

Installation

go get github.com/unifra20/ethclient

Features

Modified functions:

  • HeaderByNumber - Fetches a header by number from unifra bundle api and caches headers range in client side
  • BlockByNumber - Fetches a block by number from unifra bundle api and caches blocks range in client side

Added functions:

  • BlockReceiptsByNumber - Fetches a block receipts by number from unifra bundle api and caches receipts range in client side
  • BlockTraceByNumber - Fetches a block trace by number from unifra bundle api and caches traces range in client side
  • TransactionTraceByHash - Fetches a transaction trace by hash from unifra node

Usage

Sample

package main

import (
	"context"
	"fmt"
	"math/big"
	"time"

	"github.com/unifra20/ethclient"
)

func main() {
	_unifraBundleAPI := "https://eth-mainnet.unifra.io/v1/f7530c7a69314a6da8c430d96f10de64"
	ec, _ := ethclient.Dial(_unifraBundleAPI)
	ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)

	// BlockByNumber
	bn := big.NewInt(10000000)
	block, err := ec.BlockByNumber(ctx, bn)
	if err != nil {
		panic(err)
	}
	fmt.Printf("BlockByNumber Hash: %s\n", block.Hash().Hex())

	// HeaderByNumber
	header, err := ec.HeaderByNumber(ctx, bn)
	if err != nil {
		panic(err)
	}
	fmt.Printf("HeaderByNumber Hash: %s\n", header.Hash().Hex())

	// BlockReceipts
	receipts, err := ec.BlockReceiptsByNumber(ctx, bn)
	if err != nil {
		panic(err)
	}
	fmt.Printf("BlockReceiptsByNumber Frist Hash: %s\n", receipts[0].BlockHash.Hex())

	// BlockTraceByNumber
	btrace, err := ec.BlockTraceByNumber(ctx, bn)
	if err != nil {
		panic(err)
	}
	fmt.Printf("BlockTraceByNumber Frist Hash: %s\n", btrace[0].BlockHash.Hex())

	// TransactionTraceByHash
	txtrace, err := ec.TransactionTraceByHash(ctx, *btrace[0].TransactionHash)
	if err != nil {
		panic(err)
	}
	fmt.Printf("TransactionTraceByHash Frist Hash: %s\n", txtrace[0].BlockHash.Hex())
}

ethclient's People

Contributors

paul-unifra avatar shu-unifra avatar danielsunifra avatar

Stargazers

 avatar

Watchers

Terry Guo avatar pop-pop avatar Iron Lu avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.