Home

Awesome

elm-ethereum elm-ethereum

Examples:
Simple starter example
Complex example SPA Dapp

Cool Feature: See here how you can easily track the block depth of transactions after they've been mined.


This library allows you to interact with the Ethereum blockchain much like purescript-web3, ethers.js, or web3.js. You can hook into web wallets like MetaMask and send transactions, as well as perform read-only operations on smart contracts.

See why elm?

Setup

    import Eth
    import Eth.Types exposing (..)


    type alias Model =
        { ethNode : HttpProvider }

    init =
        { ethNode = "https://mainnet.infura.com/" }

It's good to keep the node url in your model. This way it can be kept in sync with MetaMask. Example code of this "sync" pattern to come.

Examples

    getMyBalanceInHistory : Int -> Task Http.Error BigInt
    getMyBalanceInHistory blockNum =
        Eth.getBalanceAtBlock model.ethNode myAddress (BlockNum blockNum)
    findNewestContracts : Task String (List Address)
    findNewestContracts =
        Eth.getBlockNumber model.ethNode
            |> Task.andThen (Eth.getBlock model.ethNode)
            |> Task.andThen
                (\block ->
                    block.transactions
                        |> List.map (Eth.getTxReceipt model.ethNode)
                        |> Task.sequence
                )
            |> Task.map (MaybeExtra.values << List.map .contractAddress)
            |> Task.mapError prettifyHttpError

This is an example of Railway Oriented Programming. A great video by Scott Wlaschin.

Why Elm

I'd sum up the experience of programming in Elm with two words: Fearless Refactoring

This is by no means the only pleasantry the fine tree has to offer.

Elm's claim to fame is zero runtime exceptions. It's compiler and static types are your best friends. Both from an error catching standpoint, but just as importantly, from a domain modeling standpoint.

Union Types allow you to fully leverage the compiler when modeling your business domain. See BlockId or NetworkId for instance.

Union types also allow you to hide implementation details by implementing "opaque types". An Address is just a string under the hood, but you can never directly touch that string.

Why else

    Javascript                    Elm
    ---------------------------------
    npm/yarn                 built in
    Webpack                  built in
    React                    built in
    Redux                    built in
    Typescript/Flow          built in
    Immutable.JS             built in

Contributing

Pull requests and issues are greatly appreciated!
If you think there's a better way to implement parts of this library, I'd love to hear your feedback.

Feed the tree some ether

🌳Ξ🌳Ξ🌳