blockscout

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 0 Imported by: 0

README

blockscout-api

Go Reference Go Report Card

Golang-client for blockscout.com (and its family), with almost complete implementation (accounts, transactions, tokens, contracts, blocks, epoch)

  • RPC API Endpoints
  • ETH RPC API
  • REST API

While there are several explores available to blockchain projects, most are closed systems (ie Etherscan, Etherchain). Blockscout provides a much needed open-source alternative.

Usage

go get github.com/PositiveSecurity/blockscout-go-api

Create an API instance and off you go.

package main

import (
	"fmt"

	"github.com/PositiveSecurity/blockscout-go-api"
	"github.com/PositiveSecurity/blockscout-go-api/client"
	"github.com/PositiveSecurity/blockscout-go-api/common"
)

func main() {

	var client client.BlockScoutAPIClient

	// set your url api
	client.SetBlockScoutApiUrl(blockscout.EthMainnet)
	client.SetBlockScoutApiUrlV2(blockscout.EthMainnetV2)

	// get the current block number
	block, err := client.GetCurrentBlockRpcApi()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(block)

	// convert *big.Int to uint64
	blocknum, err := common.BigIntToUint64(block)
	if err != nil {
		fmt.Println(err)
	}

	// get the ETH balance  of vitalik.eth on the current block number
	addr := "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
	balance, err := client.GetBalance(addr, blocknum)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(balance)

	// api v2
	body, err := client.GetBlockInfo("0")
	if err != nil {
		fmt.Println(err)
	}

	// print json
	common.PrettyPrintJSON(body)

}

Documentation

Overview

Package blockscout provides Go bindings to the blockscout.com API. Example can be found at https://github.com/PositiveSecurity/blockscout-go-api/

Index

Constants

View Source
const (
	EthMainnet   = "https://eth.blockscout.com/api"
	EthMainnetV2 = "https://eth.blockscout.com/api/v2/"

	GnosisV2 = "https://gnosis.blockscout.com/api/v2/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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