@hackage web30.9.1.0
Web3 API for Haskell.
Categories
License
BSD-3-Clause
Maintainer
mail@akru.me
Links
Versions
Installation
Dependencies (43)
- OneTuple >=0.2.1 && <0.3
- aeson >=1.2.2.0 && <1.5
- async >=2.1.1.1 && <2.3
- attoparsec >=0.13.2.1 && <0.14
- base >4.11 && <4.14
- base58string >=0.10.0 && <0.11 Show all…
Dependents (2)
@hackage/acme-everything, @hackage/azimuth-hs
Package Flags
compiler
(off by default)
Enable Solidity compiler
debug
(off by default)
Enable debug compiler options
Web3 API for Haskell
This library implements Haskell API client for popular Web3 platforms.
Install
stack install web3
Usage
{-# LANGUAGE OverloadedStrings #-}
module Main where
-- Basic imports
import Network.Ethereum
import Network.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.