etherego

package module
v0.0.0-...-63b2aab Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: MIT Imports: 9 Imported by: 0

README

etherego

Ethereum client wrapper

I wrote this small module just for fun (and of course for educational purposes 😄)

Documentation

Index

Constants

View Source
const EtherDefaultGasLimit uint64 = 21_000

Default gas limit in ethereum network

Variables

View Source
var (
	ErrTranslation = errors.New("unable to translate values")
	ErrKeyNotECDSA = errors.New("error asserting type: publicKey is not of type *ecdsa.PublicKey")
)
View Source
var (
	WeiEth  = big.NewInt(0).Exp(big.NewInt(10), big.NewInt(18), nil)
	GweiEth = big.NewInt(0).Exp(big.NewInt(10), big.NewInt(9), nil)
)

Functions

func EthToGWei

func EthToGWei(eth *big.Float) (*big.Int, error)

func EthToWei

func EthToWei(eth *big.Float) (*big.Int, error)

EthToWei returns eth admount in wei

func GWeiToEth

func GWeiToEth(gwei *big.Int) (*big.Float, error)

GWeiToEth returns ETH amount of gwei

func WeiToEth

func WeiToEth(wei *big.Int) (*big.Float, error)

WeiToEth returns wei amount in eth

Types

type Accounts

type Accounts map[string]string

Accounts it's a mapping of account address to account private key

type ETHClient

type ETHClient struct {
	// *ethclient.Client composition
	*ethclient.Client
	Accounts *Accounts
}

ETHClient wraps *ethclient.Client

func New

func New(addr string, accs *Accounts) (*ETHClient, error)

New ETHClient

func (*ETHClient) BlocksRange

func (e *ETHClient) BlocksRange(ctx context.Context, beg, end int) ([]*types.Block, error)

BlocksRange returns blocks by range

func (*ETHClient) SubscribeNewBlocks

func (e *ETHClient) SubscribeNewBlocks(ctx context.Context) (
	<-chan *types.Header, <-chan error, error)

SubscribeNewBlocks subscribes to new block creation events. Works only with (ws/wss):// connection scheme

func (*ETHClient) TransactionFrom

func (e *ETHClient) TransactionFrom(ctx context.Context, tx *types.Transaction) (string, error)

TransactionFrom returns transaction sender address

func (*ETHClient) TransferTokens

func (e *ETHClient) TransferTokens(ctx context.Context,
	fromAddr, toAddr string, gasLimit, ethVal *big.Int) (txHash common.Hash, err error)

TransferTokens transfer tokens from one account to another, and returns transaction hash

Jump to

Keyboard shortcuts

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