Giter VIP home page Giter VIP logo

govalent's Introduction

Govalent

govalent is a go client for Covalent Rest APIs

Installation

go get github.com/AlchemistsLab/govalent

Usage without a Client

If you are dealing with one account, there is no need to create a new client. you can simply call govalent.$resource$()

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
)

// Setup
govalent.APIKey = ""
info, err := govalent.ClassA().HistoricalPortfolio(
	"56", "0xb1b3f0e569a19E407cEb7bFAEA3486F0D9d2488B")
if err != nil {
	fmt.Printf("err = %v", err)
	return
}
fmt.Printf("%v", info)

Usage with a Client

If you are dealing with multiple accounts, You can create a new govalent.Client by the following

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
)
client := govalent.Client{}
client.Init("YOUR_API_KEY")
info, err := client.ClassA.HistoricalPortfolio(
	"56", "0xb1b3f0e569a19E407cEb7bFAEA3486F0D9d2488B")
if err != nil {
	fmt.Printf("err = %v", err)
	return
}
fmt.Printf("%v", info)

Class A endpoints

Get Chains

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
)

func main() {
	govalent.APIKey = ""
	chains, err := govalent.ClassA().Chains()
	if err != nil {
		fmt.Printf("err = %v", err)
		return
	}
	fmt.Println("Get All chains")
	for _, chain := range chains.Items {
		fmt.Printf("Chain[%v/%v]\n", chain.ID, chain.Name)
	}
	fmt.Println("Get All chain statuses")
	chainStatus, err := govalent.ClassA().ChainsStatus()
	if err != nil {
		fmt.Printf("err = %v", err)
		return
	}
	for _, chain := range chainStatus.Items {
		fmt.Printf("Chain[%v/%v], BlockHeight: %v\n", chain.ID, chain.Name, chain.SyncedBlockHeight)
	}
}

Get Token Balances

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
	"github.com/AlchemistsLab/govalent/class_a"
)

balanceParams := class_a.BalanceParams{
	Nft: true,
}

p, err := govalent.ClassA().TokenBalances(
	"56", "0xb1b3f0e569a19E407cEb7bFAEA3486F0D9d2488B", balanceParams)
if err != nil {
	fmt.Printf("err = %v", err)
	return
}
fmt.Printf("%v", p)

Get Historical Portfolio

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
)

p, err := govalent.ClassA().HistoricalPortfolio(
	"56", "0xb1b3f0e569a19E407cEb7bFAEA3486F0D9d2488B")
if err != nil {
	fmt.Printf("err = %v", err)
	return
}
fmt.Printf("%v", p)

Get Transactions

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
)

p, err := govalent.ClassA().Transactions(
	"56", "0xb1b3f0e569a19E407cEb7bFAEA3486F0D9d2488B")
if err != nil {
	fmt.Printf("err = %v", err)
	return
}
fmt.Printf("%v", p)

Get ERC20 token transfers

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
	"github.com/AlchemistsLab/govalent/class_a"
)

params := class_a.TransferParams{
    ContractAddress: "0x8a0C542bA7bBBab7cF3551fFcc546CdC5362d2a1",
}
p, err := govalent.ClassA().ERCTokenTransfers(
	"56", "0xb1b3f0e569a19E407cEb7bFAEA3486F0D9d2488B", params)
if err != nil {
	fmt.Printf("err = %v", err)
	return
}
fmt.Printf("%v", p)

Get Log Events by contract address.

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
	"github.com/AlchemistsLab/govalent/class_a"
)

params := class_a.LogEventsParams{
	StartingBlock: "9601459",
	EndingBlock: "9999800",
}
p, err := govalent.ClassA().LogEventsByContract(
	"1", "0xc0da01a04c3f3e0be433606045bb7017a7323e38", params)
if err != nil {
	fmt.Printf("err = %v", err)
	return
}
fmt.Printf("%v", p)

Class B endpoints

Get Sushiswap address exchange liquidity transactions

import (
	"fmt"
	"github.com/AlchemistsLab/govalent"
	"github.com/AlchemistsLab/govalent/class_b"
)

func main() {
	govalent.APIKey = ""
	params := class_b.SushiSwapActsParams{
		Swaps: true,
	}
	acts, err := govalent.ClassB().SushiSwapActs(
		"137", "0x4121dD930B15742b6d2e89B41284A79320bb8503", params)
	if err != nil {
		fmt.Printf("err = %v", err)
		return
	}
	fmt.Printf("Get sushiswap act for address: %v, at:%v\n", acts.Address, acts.UpdatedAt)
	for _, a := range acts.Items {
		fmt.Printf("Act[%v]: %v. At:%v\n", a.Act, a.Description, a.ActAt)
	}
}

TODO

govalent's People

Contributors

zaebee avatar vaulverin 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.