web3: Ethereum API for Haskell

[ bsd3, library, network ] [ Propose Tags ]

Web3 is a Haskell client library for Ethereum


[Skip to Readme]
Versions [faq] 0.3.2.0, 0.3.2.1, 0.3.3.0, 0.3.4.0, 0.4.0.0, 0.4.1.0, 0.5.0.0, 0.5.1.0, 0.5.2.0, 0.5.2.1, 0.5.3.0, 0.5.4.0, 0.5.5.0, 0.6.0.0, 0.7.0.0, 0.7.1.0, 0.7.2.0, 0.7.3.0, 0.8.0.0, 0.8.1.0, 0.8.2.0, 0.8.2.1, 0.8.3.0, 0.8.3.1, 0.8.3.2
Change log CHANGELOG.md
Dependencies aeson (>=1.1.2.0 && <1.5), async (>=2.1.1.1 && <2.3), base (>4.10 && <4.13), basement (>=0.0.4 && <0.1), bytestring (>=0.10.8.1 && <0.11), cereal (>=0.5.4.0 && <0.6), cryptonite (>=0.23 && <0.26), data-default (>=0.7.1.1 && <0.8), exceptions (>=0.8.3 && <0.11), generics-sop (>=0.3.1.0 && <0.6), http-client (>=0.5.7.1 && <0.7), http-client-tls (>=0.3.5.1 && <0.4), machines (>=0.6.3 && <0.8), memory (>=0.14.11 && <0.15), microlens (>=0.4.8.1 && <0.5), microlens-aeson (>=2.2.0.2 && <2.4), microlens-mtl (>=0.1.11.0 && <0.2), microlens-th (>=0.4.1.1 && <0.5), mtl (>=2.2.1 && <2.3), OneTuple (>=0.2.1 && <0.3), parsec (>=3.1.11 && <3.2), relapse (>=1.0.0.0 && <2.0), tagged (>=0.8.5 && <0.9), template-haskell (>=2.12 && <2.15), text (>=1.2.2.2 && <1.3), transformers (>=0.5.2.0 && <0.6), uuid-types (>=1.0.3 && <1.1), vinyl (>=0.5.3 && <0.12) [details]
License BSD-3-Clause
Copyright (c) Alexander Krupenkin 2016
Author Alexander Krupenkin
Maintainer mail@akru.me
Category Network
Home page https://github.com/airalab/hs-web3#readme
Bug tracker https://github.com/airalab/hs-web3/issues
Source repo head: git clone https://github.com/airalab/hs-web3
Uploaded by akru at Mon May 13 11:51:28 UTC 2019
Distributions LTSHaskell:0.8.3.2, NixOS:0.8.3.2, Stackage:0.8.3.2
Downloads 4824 total (236 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-05-13 [all 1 reports]

Modules

[Index] [Quick Jump]

Flags

NameDescriptionDefaultType
compiler

Enable Solidity compiler

DisabledManual
debug

Enable debug compiler options

DisabledManual

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for web3-0.8.3.2

[back to package description]

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

Install

stack install web3

Usage

{-# 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.