govalent is a go client for Covalent Rest APIs
go get github.com/AlchemistsLab/govalent
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)
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)
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)
}
}
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)
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)
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)
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)
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)
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)
}
}