BSD-3-Clause licensed by Alexander Krupenkin
Maintained by

Module documentation for

Ethereum API for Haskell

The Haskell Ethereum API which implements the Generic JSON RPC.

Documentation Status Build Status Hackage Matrix Hackage LTS-13 nightly Code Triagers BSD3 License


stack install web3


{-# LANGUAGE OverloadedStrings #-}
module Main where

-- Basic imports
import           Network.Ethereum.Web3

-- Eth API support
import qualified Network.Ethereum.Api.Eth   as Eth
import           Network.Ethereum.Api.Types

-- ENS support
import qualified Network.Ethereum.Ens       as Ens

-- Lens to simple param setting
import           Lens.Micro                 ((.~))

main :: IO ()
main = do
    -- Use default provider on http://localhost:8545
    ret <- runWeb3 $ do

        -- Get address of default account
        me <- head <$> Eth.accounts

        -- Get balance of default account on latest block
        myBalance <- Eth.getBalance me Latest

        -- Get half of balance
        let halfBalance = fromWei (myBalance / 2)

        -- Use default account
        withAccount () $ do
            -- Get Ethereum address via ENS
            alice <- Ens.resolve "alice.address.on.eth"
            bob   <- Ens.resolve "bob.address.on.eth"

            -- Send transaction with value
            withParam (value .~ halfBalance) $ do

                -- Send transaction to alice account
                withParam (to .~ alice) $ send ()

                -- Send transaction to bob account
                withParam (to .~ bob) $ send ()

        -- Return sended value
        return halfBalance

    -- Web3 error handling
    case ret of
        Left e  -> error $ show e
        Right v -> print (v :: Ether)  -- Print returned value in ethers

Read more in the documentation on ReadTheDocs.



All notable changes to this project will be documented in this file.

[] 2019-05-13


  • Fixed dependencies bounds for stackage distribution
  • Optimized LANGUAGE pragmas

[] 2019-01-21


  • Fixed dependencies bounds for stackage distribution

[] 2019-01-09


  • Web3 secret storage v3 support


  • Cryptonite based ECC signer for messages and transactions, it removes secp256k1 dependency
  • Fixed dependencies bounds for stackage LTS-13

[] 2018-11-19


  • Fixed dependencies bounds for stackage distribution

[] 2018-11-07


  • Gas estimation runs when gas limit is not set before

[] 2018-10-29


  • Support vinyl-0.10 in MultiFilter module

[] 2018-10-26


  • Support for Ethereum cryptography
  • Local private key transaction signer
  • Generalized JSON-RPC monad for API methods
  • Support for multiple transaction sending methods via one Account api
  • Monad based transaction sending parametrization
  • Experimental support for solidity compiler (disabled by default)
  • Support for Ethereum mainnet ENS resolver
  • Contract typeclass with api/bytecode getters
  • Gas estimation for sending transactions
  • Contract typeclass TH generator
  • Function for creating contracts
  • Event single/multi filters
  • HexString data type
  • Personal api calls
  • Address checksum


  • package.yaml instead web3.cabal package descriptor
  • Solidity related data types and codecs moved to Data.Solidity
  • Solidity related parsers and compiler moved to Language.Solidity
  • Modules in Network.Ethereum.Web3 moved to Network.Ethereum.Api
  • fromWei/toWei from Unit typeclass now operates over Integral


  • convert function from Unit typeclass

[] 2018-05-22


  • ‘Network.Ethereum.ABI.Prim’ meta-module as primitive types and instances aggregator.
  • Stackage nightly build compatibility.


  • Potential nullable web3 type (‘Change’, ‘Block’, ‘Transaction’, etc.) fields are encoded as ‘Maybe’.

[] 2018-05-13


  • Generic JSON-RPC API documentation improvements.
  • TH generator bug fixes.


  • Generic JSON-RPC API use fixed size byte arrays.


  • ‘BlockNumber’, ‘FilterId’ types replaced by ‘Quantity’ type

[] 2018-05-02


  • TxReceipt and Eth.getTransactionReceipt JSON-RPC method.
  • Keyword escaper for TH generated names.
  • Build flag to enable TLS support.


  • Library dependencies bounds fixed for GHC 8.2.2-8.4.2 (stackage LTS + Nightly).

[] 2018-04-22


  • This file for significant changes tracking.
  • Descriptive types for all JSON-RPC method parameters and returned values (#15).
  • Widely use of basement:Word256 type for encoding.
  • Full list of ethereum abi encoding types:
    • bool: Bool
    • int256: IntN
    • uint256: UIntN
    • string: Text
    • bytes: Bytes
    • bytes32: BytesN
    • dynamic array: []
    • static array: ListN


  • Rewriten encoding engine for best performance, it now based on cereal:Serialize instead of parsec:Parser.
  • Renamed encoding type classes and methods: ABIEncode -> ABIPut, ABIDecode -> ABIGet.
  • Encoding related modules moved to Network.Ethereum.ABI.
  • Primitive abi encoding types are moved to separated modules in Network.Ethereum.ABI.Prim.
  • Contract interation related modules moved to Network.Ethereum.Contract.
  • Ethereum node communication modules stay in Network.Ethereum.Web3.
  • JSON-RPC tiny client is independent now and can be used separately.


  • Event type class, currently TH create Data.Default instance for Filter e.
  • Custom setup for live testing (it replaced by travis script).
comments powered byDisqus