node

package
v0.0.0-...-4827941 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlockNotFound       = errors.New("block not found")
	ErrTransactionNotFound = errors.New("transaction not found")
)

Functions

func ContextWithRequestID

func ContextWithRequestID(parent context.Context, id jsonrpc.ID) context.Context

Types

type Client

type Client interface {
	Requester
	Subscriber

	// URL returns the backend URL we are connected to
	URL() string

	// BlockNumber returns the current block number at head
	BlockNumber(ctx context.Context) (uint64, error)

	// NetVersion returns the netversion
	NetVersion(ctx context.Context) (string, error)

	// ChainId returns the chain id
	ChainId(ctx context.Context) (string, error)

	// EstimateGas returns the estimate gas
	EstimateGas(ctx context.Context, msg eth.Transaction) (uint64, error)

	// MaxPriorityFeePerGas (EIP1559) returns the suggested tip for block
	MaxPriorityFeePerGas(ctx context.Context) (uint64, error)

	// GasPrice (Legacy) returns the suggested gas price
	GasPrice(ctx context.Context) (uint64, error)

	// GetTransactionCount get the pending nonce for public address
	GetTransactionCount(ctx context.Context, address eth.Address, numberOrTag eth.BlockNumberOrTag) (uint64, error)

	// SendRawTransaction will send the raw signed transaction return tx hash or error
	SendRawTransaction(ctx context.Context, msg string) (string, error)

	// BlockByNumber can be used to get a block by its number
	BlockByNumber(ctx context.Context, number uint64, full bool) (*eth.Block, error)

	// BlockByNumberOrTag can be used to get a block by its number or tag (e.g. latest)
	BlockByNumberOrTag(ctx context.Context, numberOrTag eth.BlockNumberOrTag, full bool) (*eth.Block, error)

	// BlockByHash can be used to get a block by its hash
	BlockByHash(ctx context.Context, hash string, full bool) (*eth.Block, error)

	// TransactionByHash can be used to get transaction by its hash
	TransactionByHash(ctx context.Context, hash string) (*eth.Transaction, error)

	// SubscribeNewHeads initiates a subscription for newHead events
	SubscribeNewHeads(ctx context.Context) (Subscription, error)

	// SubscribeNewPendingTransactions initiates a subscription for newPendingTransaction events
	SubscribeNewPendingTransactions(ctx context.Context) (Subscription, error)

	// TransactionReceipt can be used to get a TransactionReceipt for a particular transaction
	TransactionReceipt(ctx context.Context, hash string) (*eth.TransactionReceipt, error)

	// Logs returns an array of Logs matching the passed in filter
	Logs(ctx context.Context, filter eth.LogFilter) ([]eth.Log, error)

	// IsBidirectional returns true if the under laying transport supports bidirectional features such as subscriptions
	IsBidirectional() bool
}

Client represents a connection to an ethereum node

func NewClient

func NewClient(ctx context.Context, rawURL string) (Client, error)

func NewCustomClient

func NewCustomClient(requester Requester, subscriber Subscriber) (Client, error)

type Requester

type Requester interface {
	// Request method can be used to send JSONRPC requests and receive JSONRPC responses
	Request(ctx context.Context, r *jsonrpc.Request) (*jsonrpc.RawResponse, error)
}

type Subscriber

type Subscriber interface {
	// Subscribe method can be used to subscribe via eth_subscribe
	Subscribe(ctx context.Context, r *jsonrpc.Request) (Subscription, error)
}

type Subscription

type Subscription interface {
	Response() *jsonrpc.RawResponse
	ID() string
	Ch() <-chan *jsonrpc.Notification
	Unsubscribe(ctx context.Context) error
}

type SubscriptionParams

type SubscriptionParams struct {
	Subscription string          `json:"subscription"`
	Result       json.RawMessage `json:"result"`
}

Directories

Path Synopsis
Package websocket implements a websocket connection to an Ethereum node.
Package websocket implements a websocket connection to an Ethereum node.

Jump to

Keyboard shortcuts

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