ethereum

package
v1.37.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// These are the multipliers for ether denominations.
	// Example: To get the wei value of an amount in 'douglas', use
	//
	//    new(big.Int).Mul(value, big.NewInt(params.Douglas))
	//
	Wei      = 1
	Ada      = 1e3
	Babbage  = 1e6
	Shannon  = 1e9
	Szabo    = 1e12
	Finney   = 1e15
	Ether    = 1e18
	Einstein = 1e21
	Douglas  = 1e42
)
View Source
const (
	DefaultGas      int64 = 90000
	DefaultGasPrice int64 = 1 * Shannon
)

Variables

View Source
var IdMismatch = errors.New("Ids do not match!")
View Source
var InvalidChainId = errors.New("Invalid ChainId")
View Source
var IsTest = false
View Source
var JsonRpcMessage = `{"jsonrpc":"%s","method":"%s","params":%s,"id":%v}`
View Source
var JsonRpcVersion = "2.0"

Functions

func GenerateKeyPair

func GenerateKeyPair() (string, string, string, error)

func MakePayment

func MakePayment(client Client, pk string, from string, to string, amount, gasPrice *big.Int, chainId ChainId) (string, error)

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) string

func Test

func Test(b bool) bool

Flip to Universal Test Mode

Types

type ChainId

type ChainId int64
const (
	MainNet ChainId = 1
	Morden  ChainId = 2
	Ropsten ChainId = 3
)

type Client

type Client struct {
	IsTest   bool
	Commands []string
	Chain    ChainId
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, address string) Client

Create a new Ethereum JSON-RPC client

func (Client) GasPrice

func (c Client) GasPrice() (*big.Int, error)

Get the current average gasprice

func (Client) GasPrice2

func (c Client) GasPrice2() (*big.Int, *EthGasStationResponse, error)

Get the current average gasprice via https://ethgasstation.info/json/ethgasAPI.json

func (Client) GetBalance

func (c Client) GetBalance(address string) (balanceInWei *big.Int, err error)

func (Client) Post

func (c Client) Post(jsonRpcCommand string, id int64) (*JsonRpcResponse, error)

Post a JSON-RPC Command

func (Client) SendTransaction

func (c Client) SendTransaction(chainId ChainId, pk, from string, to string, amount, gasLimit, gasPrice *big.Int, data []byte) (string, error)

Send a transaction

func (Client) Test

func (c Client) Test(b bool) bool

Flip to Test Mode

type EthGasStationResponse

type EthGasStationResponse struct {
	BlockNum float64 `json:"blockNum"`

	BlockTime float64 `json:"block_time"`
	Speed     float64 `json:"speed"`

	FastestWait float64 `json:"fastestWait"`
	Fastest     float64 `json:"fastest"`

	FastWait float64 `json:"fastWait"`
	Fast     float64 `json:"fast"`

	AverageWait float64 `json:"avgWait"`
	Average     float64 `json:"average"`

	SafeLowWait float64 `json:"safeLowWait"`
	SafeLow     float64 `json:"safeLow"`
}

type JsonRpcError

type JsonRpcError struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

type JsonRpcResponse

type JsonRpcResponse struct {
	Id             int64         `json:"id"`
	JsonRpcVersion string        `json:"jsonrpc"`
	Result         ej.RawMessage `json:"result"`
	Error          JsonRpcError  `json:"error"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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