Skip to content

Latest commit

 

History

History
213 lines (178 loc) · 3.99 KB

README.md

File metadata and controls

213 lines (178 loc) · 3.99 KB

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