web3: Ethereum API for Haskell

[ apache, library, network ] [ Propose Tags ]

Web3 is a Haskell client library for Ethereum


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
debug

Enable debug compiler options

Disabled
solidity

Enable Solidity compiler

Disabled

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

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 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, 0.8.4.0, 0.9.0.0, 0.9.1.0, 1.0.0.0
Change log CHANGELOG.md
Dependencies aeson (>=1.1.2.0 && <1.5), async (>=2.1.1.1 && <2.3), base (>4.9 && <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.4), http-client (>=0.5.7.1 && <0.6), http-client-tls (>=0.3.5.1 && <0.4), machines (>=0.6.3 && <0.7), 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), secp256k1-haskell (>=0.1.4 && <0.2), tagged (>=0.8.5 && <0.9), template-haskell (>=2.11.1.0 && <2.15), text (>=1.2.2.2 && <1.3), transformers (>=0.5.2.0 && <0.6), vinyl (>=0.5.3 && <0.11) [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 2018-11-11T12:42:36Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 15173 total (64 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for web3-0.8.2.0

[back to package description]

Ethereum API for Haskell

The Haskell Ethereum API which implements the Generic JSON RPC.

Documentation Status Build Status Hackage LTS-12 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.