ethunit

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 4 Imported by: 0

README

Ethereum Units

Simple library to convert between Ethereum units.

example

func printTransaction(w io.Writer, tx *types.Transaction) error {
	value := ConvertInt(tx.Value(), Wei, Ether)
	cost := ConvertInt(tx.Cost(), Wei, Ether)
	price := ConvertInt(tx.GasPrice(), Wei, Gwei)
	_, err := fmt.Fprintf(w, `  Transaction: %s
         Data: %x
        Value: %s Ether
      Tx Cost: %s Ether
    Gas Price: %s Gwei
        Nonce: %d
`,
		tx.Hash().String(),
		tx.Data(),
		value.Text('f', 9),
		cost.Text('f', 9),
		price.Text('f', 4),
		tx.Nonce())

	return err
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertFloat

func ConvertFloat(from *big.Float, fromUnit, toUnit Unit) *big.Float

func ConvertInt

func ConvertInt(from *big.Int, fromUnit, toUnit Unit) *big.Float

Types

type Unit

type Unit int
const (
	Wei Unit = iota * 3
	Kwei
	Mwei
	Gwei
	Szabo
	Finney
	Ether
	Kether
	Mether
	Gether
	Tether
)

func Atou

func Atou(s string) (Unit, error)

Jump to

Keyboard shortcuts

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