ethgo

package module
v0.0.0-...-007bb23 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: MPL-2.0 Imports: 8 Imported by: 0

README

Eth-Go

Ethgo is a lightweight SDK in Go to interact with Ethereum compatible blockchains.

Ethgo provides the next key features:

  • Simple: Light and with a small number of direct dependencies.

  • Ethereum ecosystem: Native integration with other tools from the ecosystem like ens and etherscan.

  • Command-line-interface: Ethgo is both a Golang SDK library and a CLI.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ZeroAddress is an address of all zeros
	ZeroAddress = Address{}

	// ZeroHash is a hash of all zeros
	ZeroHash = Hash{}
)

Functions

func Ether

func Ether(i uint64) *big.Int

Ether converts a value to the ether unit with 18 decimals

func Gwei

func Gwei(i uint64) *big.Int

Gwei converts a value to the gwei unit with 9 decimals

func Keccak256

func Keccak256(v ...[]byte) []byte

Keccak256 calculates the Keccak256

Types

type AccessEntry

type AccessEntry struct {
	Address Address `json:"address"`
	Storage []Hash  `json:"storageKeys"`
}

type AccessList

type AccessList []AccessEntry

func (*AccessList) Copy

func (a *AccessList) Copy() AccessList

func (*AccessList) MarshalRLPTo

func (a *AccessList) MarshalRLPTo(dst []byte) ([]byte, error)

func (*AccessList) MarshalRLPWith

func (a *AccessList) MarshalRLPWith(arena *fastrlp.Arena) (*fastrlp.Value, error)

func (*AccessList) UnmarshalRLP

func (a *AccessList) UnmarshalRLP(buf []byte) error

func (*AccessList) UnmarshalRLPWith

func (a *AccessList) UnmarshalRLPWith(v *fastrlp.Value) error

type Address

type Address [20]byte

Address is an Ethereum address

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress converts bytes to an address object

func HexToAddress

func HexToAddress(str string) Address

HexToAddress converts an hex string value to an address object

func (Address) Address

func (a Address) Address() Address

Address implements the ethgo.Key interface Address method.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes returns the bytes of the Address

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText implements the marshal interface

func (Address) Sign

func (a Address) Sign(hash []byte) ([]byte, error)

Sign implements the ethgo.Key interface Sign method.

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(b []byte) error

UnmarshalText implements the unmarshal interface

type ArgBig

type ArgBig big.Int

func (ArgBig) MarshalText

func (a ArgBig) MarshalText() ([]byte, error)

func (*ArgBig) UnmarshalText

func (a *ArgBig) UnmarshalText(input []byte) error

type ArgBytes

type ArgBytes []byte

func (*ArgBytes) Bytes

func (b *ArgBytes) Bytes() []byte

func (ArgBytes) MarshalText

func (b ArgBytes) MarshalText() ([]byte, error)

func (*ArgBytes) UnmarshalText

func (b *ArgBytes) UnmarshalText(input []byte) error

type ArgUint64

type ArgUint64 uint64

func (ArgUint64) MarshalText

func (b ArgUint64) MarshalText() ([]byte, error)

func (*ArgUint64) Uint64

func (u *ArgUint64) Uint64() uint64

func (*ArgUint64) UnmarshalText

func (u *ArgUint64) UnmarshalText(input []byte) error

type Block

type Block struct {
	Number             uint64
	Hash               Hash
	ParentHash         Hash
	Sha3Uncles         Hash
	TransactionsRoot   Hash
	StateRoot          Hash
	ReceiptsRoot       Hash
	Miner              Address
	Difficulty         *big.Int
	ExtraData          []byte
	GasLimit           uint64
	GasUsed            uint64
	Timestamp          uint64
	Transactions       []*Transaction
	TransactionsHashes []Hash
	Uncles             []Hash
}

func (*Block) Copy

func (b *Block) Copy() *Block

func (*Block) MarshalJSON

func (t *Block) MarshalJSON() ([]byte, error)

MarshalJSON implements the marshal interface

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the unmarshal interface

type BlockNumber

type BlockNumber int
const (
	Latest   BlockNumber = -1
	Earliest BlockNumber = -2
	Pending  BlockNumber = -3
)

func EncodeBlock

func EncodeBlock(block ...BlockNumber) BlockNumber

func (BlockNumber) Location

func (b BlockNumber) Location() string

func (BlockNumber) String

func (b BlockNumber) String() string

type BlockNumberOrHash

type BlockNumberOrHash interface {
	Location() string
}

type CallMsg

type CallMsg struct {
	From     Address
	To       *Address
	Data     []byte
	GasPrice uint64
	Gas      *big.Int
	Value    *big.Int
}

func (*CallMsg) MarshalJSON

func (c *CallMsg) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshal interface.

type Hash

type Hash [32]byte

Hash is an Ethereum hash

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash converts bytes to a hash object

func HexToHash

func HexToHash(str string) Hash

HexToHash converts an hex string value to a hash object

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the bytes of the Hash

func (Hash) Location

func (h Hash) Location() string

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText implements the marshal interface

func (Hash) String

func (h Hash) String() string

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(b []byte) error

UnmarshalText implements the unmarshal interface

type Key

type Key interface {
	Address() Address
	Sign(hash []byte) ([]byte, error)
}

type Log

type Log struct {
	Removed          bool
	LogIndex         uint64
	TransactionIndex uint64
	TransactionHash  Hash
	BlockHash        Hash
	BlockNumber      uint64
	Address          Address
	Topics           []Hash
	Data             []byte
}

func (*Log) Copy

func (l *Log) Copy() *Log

func (*Log) MarshalJSON

func (l *Log) MarshalJSON() ([]byte, error)

MarshalJSON implements the marshal interface

func (*Log) UnmarshalJSON

func (r *Log) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the unmarshal interface

type LogFilter

type LogFilter struct {
	Address   []Address
	Topics    [][]*Hash
	BlockHash *Hash
	From      *BlockNumber
	To        *BlockNumber
}

func (*LogFilter) MarshalJSON

func (l *LogFilter) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshal interface.

func (*LogFilter) SetFromUint64

func (l *LogFilter) SetFromUint64(num uint64)

func (*LogFilter) SetTo

func (l *LogFilter) SetTo(b BlockNumber)

func (*LogFilter) SetToUint64

func (l *LogFilter) SetToUint64(num uint64)

func (*LogFilter) UnmarshalJSON

func (lf *LogFilter) UnmarshalJSON(buf []byte) error

type Network

type Network uint64

Network is a chain id

const (
	// Mainnet is the mainnet network
	Mainnet Network = 1

	// Ropsten is the POW testnet
	Ropsten Network = 3

	// Rinkeby is a POW testnet
	Rinkeby Network = 4

	// Goerli is the Clique testnet
	Goerli Network = 5
)

type Receipt

type Receipt struct {
	TransactionHash   Hash
	TransactionIndex  uint64
	ContractAddress   Address
	BlockHash         Hash
	From              Address
	BlockNumber       uint64
	GasUsed           uint64
	CumulativeGasUsed uint64
	LogsBloom         []byte
	Logs              []*Log
	Status            uint64
	To                *Address
}

func (*Receipt) Copy

func (r *Receipt) Copy() *Receipt

func (*Receipt) UnmarshalJSON

func (r *Receipt) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the unmarshal interface

type Transaction

type Transaction struct {
	Type TransactionType

	// legacy values
	Hash     Hash
	From     Address
	To       *Address
	Input    []byte
	GasPrice uint64
	Gas      uint64
	Value    *big.Int
	Nonce    uint64
	V        []byte
	R        []byte
	S        []byte

	// jsonrpc values
	BlockHash   Hash
	BlockNumber uint64
	TxnIndex    uint64

	// eip-2930 values
	ChainID    *big.Int
	AccessList AccessList

	// eip-1559 values
	MaxPriorityFeePerGas *big.Int
	MaxFeePerGas         *big.Int
}

func (*Transaction) Copy

func (t *Transaction) Copy() *Transaction

func (*Transaction) GetHash

func (t *Transaction) GetHash() (hash Hash, err error)

GetHash returns the Hash of the transaction

func (*Transaction) MarshalJSON

func (t *Transaction) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshal interface.

func (*Transaction) MarshalRLPTo

func (t *Transaction) MarshalRLPTo(dst []byte) ([]byte, error)

MarshalRLPTo marshals the transaction to a []byte destination

func (*Transaction) MarshalRLPWith

func (t *Transaction) MarshalRLPWith(arena *fastrlp.Arena) (*fastrlp.Value, error)

MarshalRLPWith marshals the transaction to RLP with a specific fastrlp.Arena

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the unmarshal interface

func (*Transaction) UnmarshalRLP

func (t *Transaction) UnmarshalRLP(buf []byte) error

func (*Transaction) UnmarshalRLPWith

func (t *Transaction) UnmarshalRLPWith(v *fastrlp.Value) error

type TransactionType

type TransactionType int
const (
	TransactionLegacy TransactionType = 0
	// eip-2930
	TransactionAccessList TransactionType = 1
	// eip-1559
	TransactionDynamicFee TransactionType = 2
)

Directories

Path Synopsis
builtin
ens
Code generated by ethgo/abigen.
Code generated by ethgo/abigen.
erc20
Code generated by ethgo/abigen.
Code generated by ethgo/abigen.
cmd module

Jump to

Keyboard shortcuts

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