govalent

package module
v0.0.0-...-33f150c Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: GPL-3.0 Imports: 5 Imported by: 1

README

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

Documentation

Overview

Package govalent provides the binding for Covalent Rest APIs.

Index

Constants

View Source
const (
	APIURL = "https://api.covalenthq.com/v1/"
)

constant used for API client

Variables

View Source
var APIKey string

APIKey is Covalent API Key.

Functions

func ClassA

func ClassA() *class_a.Client

ClassA uses endpoint without client.

func ClassB

func ClassB() *class_b.Client

ClassB uses endpoint without client.

Types

type Client

type Client struct {
	ClassA class_a.Client
	ClassB class_b.Client
}

Client is the Covalent client. It contains all resources available.

func (*Client) Init

func (c *Client) Init(apiKey string)

Init initializes the covalent client with given API key, secret key.

Directories

Path Synopsis
Package class_a general provides the binding for Covalent Rest APIs Class A endpoints.
Package class_a general provides the binding for Covalent Rest APIs Class A endpoints.
Package class_b general provides the binding for Covalent Rest APIs Class B endpoints.
Package class_b general provides the binding for Covalent Rest APIs Class B endpoints.
Package client contains methods to make request to Covalent API server.
Package client contains methods to make request to Covalent API server.

Jump to

Keyboard shortcuts

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