cmditch/elm-ethereum/3.0.3

NOTE: the latest version is 5.0.0

Eth.Units

Conversions and Helpers

Concise Units

Useful helpers for concise value declarations.

txParams : Send
txParams =
    { to = Just myContract
    , from = Nothing
    , gas = Nothing
    , gasPrice = Just (gwei 3)
    , value = Just (eth 3)
    , data = Just data
    , nonce = Nothing
    }
gwei : Int -> BigInt
eth : Int -> BigInt

Precise Units

Helpers for dealing with floats.

type EthUnit
= Wei
| Kwei
| Mwei
| Gwei
| Microether
| Milliether
| Ether
| Kether
| Mether
| Gether
| Tether

Eth Unit Useful for displaying to, and taking user input from, the UI

toWei : EthUnit -> String -> Result String BigInt

Convert a given stringy EthUnit to it's Wei equivalent

toWei Gwei "50" == Ok (BigInt.fromInt 50000000000)


toWei Wei "40.9123" == Ok (BigInt.fromInt 40)


toWei Kwei "40.9123" == Ok (BigInt.fromInt 40912)


toWei Gwei "ten" == Err
fromWei : EthUnit -> BigInt -> String

Convert stringy Wei to a given EthUnit

fromWei Gwei (BigInt.fromInt 123456789) == "0.123456789"


fromWei Ether (BigInt.fromInt 123456789) == "0.000000000123456789"

Note Do not pass anything larger than MAX_SAFE_INTEGER into BigInt.fromInt MAX_SAFE_INTEGER == 9007199254740991

bigIntToWei : EthUnit -> BigInt -> BigInt

Convert a given BigInt EthUnit to it's Wei equivalent