rpc

package
v0.0.0-...-5a544cf Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 15 Imported by: 8

Documentation

Overview

Package rpc invokes JSON-RPC with ethereum node

Index

Constants

View Source
const (
	// Mainnet is a const string indicates mainnet
	Mainnet = "MAIN"
	// Testnet is a const string indicates testnet
	Testnet = "TEST"
)
View Source
const ContentType = "application/json"

ContentType is a content-type for JSON-RPC

Variables

View Source
var MainnetUrls = []string{""}

MainnetUrls is a URL list for mainnet

View Source
var (

	// NetType is either mainnet or testnet
	NetType = Testnet
)
View Source
var TestnetUrls = []string{"REPLACE WITH YOUR NODE URL #1", "REPLACE WITH YOUR NODE URL #2"} //ex.  "https://api.metadium.com/dev"

TestnetUrls is a URL list for testnet

Functions

This section is empty.

Types

type RPC

type RPC struct {
	NetType    string
	NetVersion *big.Int

	GasPrice uint64
	// contains filtered or unexported fields
}

RPC is a JSON-RPC manager through HTTP

func GetInstance

func GetInstance() *RPC

GetInstance returns the instance of RPC

func (*RPC) Call

func (r *RPC) Call(to, data string) (string, error)

Call invokes RPC "eth_call"

func (*RPC) DoRPC

func (r *RPC) DoRPC(req interface{}) (ret string, err error)

DoRPC invokes HTTP post request to ethereum node Retry when fail, give penalty to low-latency node

func (*RPC) GetChainID

func (r *RPC) GetChainID() *big.Int

GetChainID invokes RPC "net_version"

func (*RPC) GetCode

func (r *RPC) GetCode(addr string) (string, error)

GetCode invokes RPC "eth_getCode"

func (*RPC) GetEthClient

func (r *RPC) GetEthClient() *ethclient.Client

GetEthClient returns ether client among urls included in target net

func (*RPC) GetGasPrice

func (r *RPC) GetGasPrice() uint64

GetGasPrice invokes RPC "eth_gasPrice"

func (*RPC) GetTransactionCount

func (r *RPC) GetTransactionCount(addr string) uint64

GetTransactionCount invokes RPC "eth_getTransactionCount"

func (*RPC) InitClient

func (r *RPC) InitClient()

InitClient initializes HTTP client to reduce handshaking overhead

func (*RPC) SendRawTransaction

func (r *RPC) SendRawTransaction(raw []byte) (string, error)

SendRawTransaction invokes RPC "eth_sendRawTransaction"

func (*RPC) SendTransaction

func (r *RPC) SendTransaction(from, to, data string, gas int) (string, error)

SendTransaction invokes RPC "eth_sendTransaction"

Jump to

Keyboard shortcuts

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