web3-0.8.2.1: Ethereum API for Haskell

CopyrightAlexander Krupenkin 2016-2018
LicenseBSD3
Maintainermail@akru.me
Stabilityexperimental
Portabilityunportable
Safe HaskellSafe
LanguageHaskell2010

Network.Ethereum.Unit

Contents

Description

Ethereum has a metric system of denominations used as units of ether. Each denomination has its own unique name (some bear the family name of seminal figures playing a role in evolution of computer science and cryptoeconomics). The smallest denomination aka base unit of ether is called Wei. Below is a list of the named denominations and their value in Wei. Following a common (although somewhat ambiguous) pattern, ether also designates a unit (of 1e18 or one quintillion Wei) of the currency. Note that the currency is not called Ethereum as many mistakenly think, nor is Ethereum a unit.

In Haskell the Ethereum unit system presented as set of types: Wei, Szabo, Finney, etc. They are members of Unit typeclass. Also available standart Show, Read, Num operations over Ethereum units.

> let x = 1.2 :: Ether
> toWei x
1200000000000000000

> let y = x + 2
> y
3.20 ether

> let z = 15 :: Szabo
> y + z

interactive:6:5: error:
   • Couldn't match type ‘Network.Ethereum.Unit.U4’
                   with ‘Network.Ethereum.Unit.U6’
     Expected type: Ether
     Actual type: Szabo
Synopsis

The Unit type class

class (Read a, Show a, UnitSpec a, Fractional a) => Unit a where Source #

Ethereum value unit

Minimal complete definition

fromWei, toWei

Methods

fromWei :: Integral b => b -> a Source #

Make a value from integer wei

toWei :: Integral b => a -> b Source #

Convert a value to integer wei

Ethereum value metrics

type Wei = Value U0 Source #

Wei unit type

type Babbage = Value U1 Source #

Babbage unit type

type Lovelace = Value U2 Source #

Lovelace unit type

type Shannon = Value U3 Source #

Shannon unit type

type Szabo = Value U4 Source #

Szabo unit type

type Finney = Value U5 Source #

Finney unit type

type Ether = Value U6 Source #

Ether unit type

type KEther = Value U7 Source #

KEther unit type